Skip to content

Commit

Permalink
[ENG-2684] Fix bug timezone parsing for timestamp literals
Browse files Browse the repository at this point in the history
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
  • Loading branch information
m-iancu committed Mar 8, 2018
1 parent 4902d06 commit 679b57b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/yb/util/date_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::regex> regexes {
Expand Down

0 comments on commit 679b57b

Please sign in to comment.