Skip to content

Commit

Permalink
Update ExprTimeValue by datetimeValue and other interfaces. Add c…
Browse files Browse the repository at this point in the history
…orresponding tests.

Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Oct 13, 2022
1 parent db18570 commit 40ffca2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

import static org.opensearch.sql.utils.DateTimeFormatters.TIME_FORMATTER_VARIABLE_NANOS;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Objects;
Expand Down Expand Up @@ -51,6 +56,21 @@ public LocalTime timeValue() {
return time;
}

@Override
public LocalDate dateValue() {
return LocalDate.now();
}

@Override
public LocalDateTime datetimeValue() {
return LocalDateTime.of(dateValue(), timeValue());
}

@Override
public Instant timestampValue() {
return ZonedDateTime.of(dateValue(), timeValue(), ZoneId.systemDefault()).toInstant();
}

@Override
public String toString() {
return String.format("TIME '%s'", value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public void timeValueInterfaceTest() {

assertEquals(TIME, timeValue.type());
assertEquals(LocalTime.parse("01:01:01"), timeValue.timeValue());
assertEquals(LocalDate.now(), timeValue.dateValue());
assertEquals(LocalDate.now().atTime(1, 1, 1), timeValue.datetimeValue());
assertEquals(ZonedDateTime.of(LocalTime.parse("01:01:01").atDate(LocalDate.now()),
ZoneId.systemDefault()).toInstant(), timeValue.timestampValue());
assertEquals("01:01:01", timeValue.value());
assertEquals("TIME '01:01:01'", timeValue.toString());
assertThrows(ExpressionEvaluationException.class, () -> integerValue(1).timeValue(),
Expand Down

0 comments on commit 40ffca2

Please sign in to comment.