From 679b57b28c49d1bec9f4e57707eef48092677d07 Mon Sep 17 00:00:00 2001 From: Mihnea Iancu Date: Sun, 11 Feb 2018 15:37:38 +0200 Subject: [PATCH] [ENG-2684] Fix bug timezone parsing for timestamp literals Summary: Minor fix in the timestamp regex to avoid the bad parses. Enhancing the timezone support will be done in a followup commit. Test Plan: TestTimestampDataType Reviewers: neil, robert Reviewed By: robert Subscribers: yql Differential Revision: https://phabricator.dev.yugabyte.com/D4110 --- .../src/test/java/org/yb/cql/TestTimestampDataType.java | 4 ++++ src/yb/util/date_time.cc | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/java/yb-cql/src/test/java/org/yb/cql/TestTimestampDataType.java b/java/yb-cql/src/test/java/org/yb/cql/TestTimestampDataType.java index 522e540debff..a37e7264e07a 100644 --- a/java/yb-cql/src/test/java/org/yb/cql/TestTimestampDataType.java +++ b/java/yb-cql/src/test/java/org/yb/cql/TestTimestampDataType.java @@ -118,6 +118,10 @@ public void testInvalidInsert() throws Exception { runInvalidInsert(tableName, "1992-13-12"); runInvalidInsert(tableName, "1992-12-12 14:23:30:31"); runInvalidInsert(tableName, "1992-12-12 14:23:30.12.32"); + runInvalidInsert(tableName, "2017-12-21 00:00:01+0000"); + runInvalidInsert(tableName, "2017-12-21 00:00:01.000+123:30"); + runInvalidInsert(tableName, "2017-12-21 00:00:01.0000"); + runInvalidInsert(tableName, "2017-12-21 00:00:01.000000+0000"); } @Test diff --git a/src/yb/util/date_time.cc b/src/yb/util/date_time.cc index 136c9fe61e2e..a888fccc7c85 100644 --- a/src/yb/util/date_time.cc +++ b/src/yb/util/date_time.cc @@ -173,8 +173,12 @@ DateTimeInputFormat DateTime::CqlDateTimeInputFormat = []() -> DateTimeInputForm string time_fmt_no_sec = "(\\d{1,2}):(\\d{1,2})" + fmt_empty; string time_empty = fmt_empty + fmt_empty + fmt_empty; string frac_fmt = "\\.(\\d{1,3})"; - string tzX_fmt = "((?:\\+|-).+)"; - string tzZ_fmt = " (.+)"; + // Offset, i.e. +/-xx:xx + string tzX_fmt = "((?:\\+|-)\\d{2}:\\d{2})"; + // Timezone name, abbreviation, or offset (preceded by space), e.g. PDT, UDT+/-xx:xx, etc.. + // At this point this allows anything that starts with a letter or '+' (after space), and leaves + // further processing to the timezone parser. + string tzZ_fmt = " ([a-zA-Z\\+].+)"; // These cases match the valid Cassandra input formats vector regexes {