Skip to content

Commit

Permalink
Adding more test cases for datetime and milliseconds for DATE and TIM…
Browse files Browse the repository at this point in the history
…E functions.

Signed-off-by: MitchellGale-BitQuill <[email protected]>
  • Loading branch information
MitchellGale committed Oct 19, 2022
1 parent f9e38e9 commit 2016222
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
@RequiredArgsConstructor
public class ExprDateValue extends AbstractExprValue {

//private static final DateTimeFormatter DATE_FORMATTER_VARIABLE_NANOS_OPTIONAL = ;
private final LocalDate date;

/**
* Constructor of ExprDateValue.
*/
public ExprDateValue(String date) {
try {
this.date = LocalDate.parse(date, DATE_FORMATTER_VARIABLE_NANOS_OPTIONAL);
this.date = LocalDate.parse(date, DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL);
} catch (DateTimeParseException e) {
throw new SemanticCheckException(String.format("date:%s in unsupported format, please use "
+ "yyyy-MM-dd", date));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ExprTimeValue extends AbstractExprValue {
*/
public ExprTimeValue(String time) {
try {
this.time = LocalTime.parse(time, TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL);
this.time = LocalTime.parse(time, DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL);
} catch (DateTimeParseException e) {
throw new SemanticCheckException(String.format("time:%s in unsupported format, please use "
+ "HH:mm:ss[.SSSSSSSSS]", time));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,9 @@ private ExprValue exprSubDateInterval(ExprValue date, ExprValue expr) {
* @return ExprValue.
*/
private ExprValue exprTime(ExprValue exprValue) {
if (exprValue.type() == DATE) {
return new ExprTimeValue("00:00:00");
}
if (exprValue instanceof ExprStringValue) {
try {
return new ExprTimeValue(exprValue.stringValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class DateTimeFormatters {

public static final DateTimeFormatter DATE_FORMATTER_VARIABLE_NANOS_OPTIONAL =
new DateTimeFormatterBuilder()
.appendPattern("[uu:MM:dd][uuuu-MM-dd HH:mm:ss][uuuu-MM-dd]")
.appendPattern("[uuuu-MM-dd][HH:mm:ss][uuuu-MM-dd HH:mm:ss]")
.appendFraction(
ChronoField.NANO_OF_SECOND,
MIN_FRACTION_SECONDS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ public void date() {
assertEquals(DATE, expr.type());
assertEquals(new ExprDateValue(LocalDate.now()), expr.valueOf(null));


expr = dsl.date(DSL.literal("2020-02-30"));
assertEquals(nullValue(), expr.valueOf(null));
}
Expand Down Expand Up @@ -810,11 +809,20 @@ public void time() {
assertEquals(new ExprTimeValue("01:01:01"), eval(expr));
assertEquals("time(TIME '01:01:01')", expr.toString());

expr = dsl.time(DSL.literal(new ExprTimeValue("2020-01-02 01:01:01")));
expr = dsl.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01:01")));
assertEquals(TIME, expr.type());
assertEquals(new ExprTimeValue("2020-01-02 01:01:01"), eval(expr));
assertEquals(new ExprTimeValue("2019-04-19 01:01:01"), eval(expr));
assertEquals("time(TIME '01:01:01')", expr.toString());

expr = dsl.time(DSL.literal(new ExprTimeValue("01:01:01.0123")));
assertEquals(TIME, expr.type());
assertEquals(new ExprTimeValue("01:01:01.0123"), eval(expr));
assertEquals("time(TIME '01:01:01.0123')", expr.toString());

expr = dsl.time(dsl.date(DSL.literal("2020-01-02")));
assertEquals(TIME, expr.type());
assertEquals(new ExprTimeValue("00:00:00"), expr.valueOf(null));

expr = dsl.time(DSL.literal("01:01:01:01"));
assertEquals(nullValue(), expr.valueOf(null));
}
Expand Down

0 comments on commit 2016222

Please sign in to comment.