diff --git a/engine/time/src/main/java/io/deephaven/time/TimeLiteralReplacedExpression.java b/engine/time/src/main/java/io/deephaven/time/TimeLiteralReplacedExpression.java index 693282fe0e8..012eb43d6a2 100644 --- a/engine/time/src/main/java/io/deephaven/time/TimeLiteralReplacedExpression.java +++ b/engine/time/src/main/java/io/deephaven/time/TimeLiteralReplacedExpression.java @@ -77,6 +77,7 @@ public static TimeLiteralReplacedExpression convertExpression(String expression) int nanosIndex = 0; int periodIndex = 0; int durationIndex = 0; + int tzIndex = 0; final Matcher matcher = Pattern.compile("'[^']*'").matcher(expression); @@ -129,8 +130,16 @@ public static TimeLiteralReplacedExpression convertExpression(String expression) .append(expression, matcher.start() + 1, matcher.end() - 1).append("\");\n"); newVariables.put("_localTime" + nanosIndex, LocalTime.class); nanosIndex++; + } else if (DateTimeUtils.parseTimeZoneQuiet(s) != null) { + matcher.appendReplacement(convertedFormula, "_timeZone" + tzIndex); + instanceVariablesString.append(" private java.time.ZoneId _timeZone").append(tzIndex) + .append("=DateTimeUtils.parseTimeZone(\"") + .append(expression, matcher.start() + 1, matcher.end() - 1).append("\");\n"); + newVariables.put("_timeZone" + tzIndex, ZoneId.class); + tzIndex++; } else { - throw new Exception("Cannot parse datetime/time/period : " + s); + throw new Exception( + "Cannot parse literal as a datetime, date, time, duration, period, or timezone: " + s); } } diff --git a/engine/time/src/test/java/io/deephaven/time/TestTimeLiteralReplacedExpression.java b/engine/time/src/test/java/io/deephaven/time/TestTimeLiteralReplacedExpression.java index 7d16628772e..21146d7ef1b 100644 --- a/engine/time/src/test/java/io/deephaven/time/TestTimeLiteralReplacedExpression.java +++ b/engine/time/src/test/java/io/deephaven/time/TestTimeLiteralReplacedExpression.java @@ -85,6 +85,32 @@ public void testConvertExpressionLocalTime() throws Exception { tlre.getInstanceVariablesString()); } + public void testConvertExpressionTimeZone() throws Exception { + final TimeLiteralReplacedExpression tlre = TimeLiteralReplacedExpression.convertExpression("'America/Denver'"); + TestCase.assertEquals("_timeZone0", tlre.getConvertedFormula()); + + final HashMap> newVars = new HashMap<>(); + newVars.put("_timeZone0", ZoneId.class); + TestCase.assertEquals(newVars, tlre.getNewVariables()); + + TestCase.assertEquals( + " private java.time.ZoneId _timeZone0=DateTimeUtils.parseTimeZone(\"America/Denver\");\n", + tlre.getInstanceVariablesString()); + } + + public void testConvertExpressionTimeZone2() throws Exception { + final TimeLiteralReplacedExpression tlre = TimeLiteralReplacedExpression.convertExpression("'NY'"); + TestCase.assertEquals("_timeZone0", tlre.getConvertedFormula()); + + final HashMap> newVars = new HashMap<>(); + newVars.put("_timeZone0", ZoneId.class); + TestCase.assertEquals(newVars, tlre.getNewVariables()); + + TestCase.assertEquals( + " private java.time.ZoneId _timeZone0=DateTimeUtils.parseTimeZone(\"NY\");\n", + tlre.getInstanceVariablesString()); + } + public void testConvertExpressionUnknown() throws Exception { final TimeLiteralReplacedExpression tlre = TimeLiteralReplacedExpression.convertExpression("'g'"); TestCase.assertEquals("'g'", tlre.getConvertedFormula());