From 9d3f6be8f99ef1e32dc846be2797a18c90ab88e0 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Thu, 13 Oct 2022 17:58:01 -0700 Subject: [PATCH] Fix conversion to timestamp. Signed-off-by: Yury-Fridlyand --- .../java/org/opensearch/sql/data/model/ExprDateValue.java | 2 +- .../java/org/opensearch/sql/data/model/ExprTimeValue.java | 2 +- .../java/org/opensearch/sql/data/model/DateTimeValueTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java index 09b2e56b44..2ebf0dd775 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprDateValue.java @@ -67,7 +67,7 @@ public LocalDateTime datetimeValue() { @Override public Instant timestampValue() { - return ZonedDateTime.of(date, timeValue(), ZoneId.systemDefault()).toInstant(); + return ZonedDateTime.of(date, timeValue(), ZoneId.of("UTC")).toInstant(); } @Override diff --git a/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java b/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java index 12bbfaab0f..51a7d1ba0f 100644 --- a/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java +++ b/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java @@ -68,7 +68,7 @@ public LocalDateTime datetimeValue() { @Override public Instant timestampValue() { - return ZonedDateTime.of(dateValue(), timeValue(), ZoneId.systemDefault()).toInstant(); + return ZonedDateTime.of(dateValue(), timeValue(), ZoneId.of("UTC")).toInstant(); } @Override diff --git a/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java b/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java index 9a1d92f5e0..ca6a09a30c 100644 --- a/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java +++ b/core/src/test/java/org/opensearch/sql/data/model/DateTimeValueTest.java @@ -34,7 +34,7 @@ public void timeValueInterfaceTest() { 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()); + ZoneId.of("UTC")).toInstant(), timeValue.timestampValue()); assertEquals("01:01:01", timeValue.value()); assertEquals("TIME '01:01:01'", timeValue.toString()); assertThrows(ExpressionEvaluationException.class, () -> integerValue(1).timeValue(), @@ -65,7 +65,7 @@ public void dateValueInterfaceTest() { assertEquals(LocalTime.parse("00:00:00"), dateValue.timeValue()); assertEquals(LocalDateTime.parse("2012-07-07T00:00:00"), dateValue.datetimeValue()); assertEquals(ZonedDateTime.of(LocalDateTime.parse("2012-07-07T00:00:00"), - ZoneId.systemDefault()).toInstant(), dateValue.timestampValue()); + ZoneId.of("UTC")).toInstant(), dateValue.timestampValue()); ExpressionEvaluationException exception = assertThrows(ExpressionEvaluationException.class, () -> integerValue(1).dateValue()); assertEquals("invalid to get dateValue from value of type INTEGER",