Skip to content

Commit

Permalink
Added support for HH:mm for time/datetime inputs. Removed call for lo…
Browse files Browse the repository at this point in the history
…cal time now.

Signed-off-by: MitchellGale-BitQuill <[email protected]>
  • Loading branch information
MitchellGale committed Oct 25, 2022
1 parent 95c5e5c commit 61289bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ private DefaultFunctionResolver date() {
return define(BuiltinFunctionName.DATE.getName(),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, STRING),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, DATE),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, TIME),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, DATETIME),
impl(nullMissingHandling(DateTimeFunction::exprDate), DATE, TIMESTAMP));
}
Expand Down Expand Up @@ -652,9 +651,6 @@ private ExprValue exprConvertTZ(ExprValue startingDateTime, ExprValue fromTz, Ex
* @return ExprValue.
*/
private ExprValue exprDate(ExprValue exprValue) {
if (exprValue.type() == TIME) {
return new ExprDateValue(LocalDate.now());
}
if (exprValue instanceof ExprStringValue) {
try {
return new ExprDateValue(exprValue.stringValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class DateTimeFormatters {

public static final DateTimeFormatter DATE_TIME_FORMATTER_VARIABLE_NANOS_OPTIONAL =
new DateTimeFormatterBuilder()
.appendPattern("[uuuu-MM-dd HH:mm:ss][HH:mm:ss][uuuu-MM-dd]")
.appendPattern("[uuuu-MM-dd HH:mm:ss][uuuu-MM-dd HH:mm][HH:mm:ss][HH:mm][uuuu-MM-dd]")
.appendFraction(
ChronoField.NANO_OF_SECOND,
MIN_FRACTION_SECONDS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ public void date() {
assertEquals(new ExprDateValue("2020-08-17 12:12:00"), eval(expr));
assertEquals("date(DATE '2020-08-17')", expr.toString());

expr = dsl.date(dsl.time(DSL.literal("12:12:00")));
expr = dsl.date(DSL.literal(new ExprDateValue("2020-08-17 12:12")));
assertEquals(DATE, expr.type());
assertEquals(new ExprDateValue(LocalDate.now()), expr.valueOf(null));
assertEquals(new ExprDateValue("2020-08-17 12:12"), eval(expr));
assertEquals("date(DATE '2020-08-17')", expr.toString());

expr = dsl.date(DSL.literal("2020-02-30"));
assertEquals(nullValue(), expr.valueOf(null));
Expand Down Expand Up @@ -809,11 +810,21 @@ 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("01:01")));
assertEquals(TIME, expr.type());
assertEquals(new ExprTimeValue("01:01"), eval(expr));
assertEquals("time(TIME '01:01')", expr.toString());

expr = dsl.time(DSL.literal(new ExprTimeValue("2019-04-19 01:01:01")));
assertEquals(TIME, expr.type());
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("2019-04-19 01:01")));
assertEquals(TIME, expr.type());
assertEquals(new ExprTimeValue("2019-04-19 01:01"), eval(expr));
assertEquals("time(TIME '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));
Expand Down

0 comments on commit 61289bb

Please sign in to comment.