Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(static): switch partial datetime parser to use UTC by default #3473

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static String getTimezone(final String time) {

private static ZoneId parseTimezone(final String timezone) {
if (timezone.trim().isEmpty()) {
return ZoneId.systemDefault();
return ZoneId.of("+0000");
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class PartialStringToTimestampParserTest {

private static final StringToTimestampParser FULL_PARSER =
new StringToTimestampParser(KsqlConstants.DATE_TIME_PATTERN);
new StringToTimestampParser(KsqlConstants.DATE_TIME_PATTERN + "X");

@Rule
public final ExpectedException expectedException = ExpectedException.none();
Expand All @@ -43,44 +43,44 @@ public void init() {
@Test
public void shouldParseYear() {
// When:
assertThat(parser.parse("2017"), is(fullParse("2017-01-01T00:00:00.000")));
assertThat(parser.parse("2017"), is(fullParse("2017-01-01T00:00:00.000+0000")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need all of these +0000s after this change, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we do. The 'fullParse' is expecting a tz - this makes the tests very explicit as to what timezone is expected.

}

@Test
public void shouldParseYearMonth() {
// When:
assertThat(parser.parse("2020-02"), is(fullParse("2020-02-01T00:00:00.000")));
assertThat(parser.parse("2020-02"), is(fullParse("2020-02-01T00:00:00.000+0000")));
}

@Test
public void shouldParseFullDate() {
// When:
assertThat(parser.parse("2020-01-02"), is(fullParse("2020-01-02T00:00:00.000")));
assertThat(parser.parse("2020-01-02T"), is(fullParse("2020-01-02T00:00:00.000")));
assertThat(parser.parse("2020-01-02"), is(fullParse("2020-01-02T00:00:00.000+0000")));
assertThat(parser.parse("2020-01-02T"), is(fullParse("2020-01-02T00:00:00.000+0000")));
}

@Test
public void shouldParseDateWithHour() {
// When:
assertThat(parser.parse("2020-12-02T13"), is(fullParse("2020-12-02T13:00:00.000")));
assertThat(parser.parse("2020-12-02T13"), is(fullParse("2020-12-02T13:00:00.000+0000")));
}

@Test
public void shouldParseDateWithHourMinute() {
// When:
assertThat(parser.parse("2020-12-02T13:59"), is(fullParse("2020-12-02T13:59:00.000")));
assertThat(parser.parse("2020-12-02T13:59"), is(fullParse("2020-12-02T13:59:00.000+0000")));
}

@Test
public void shouldParseDateWithHourMinuteSecond() {
// When:
assertThat(parser.parse("2020-12-02T13:59:58"), is(fullParse("2020-12-02T13:59:58.000")));
assertThat(parser.parse("2020-12-02T13:59:58"), is(fullParse("2020-12-02T13:59:58.000+0000")));
}

@Test
public void shouldParseFullDateTime() {
// When:
assertThat(parser.parse("2020-12-02T13:59:58.123"), is(fullParse("2020-12-02T13:59:58.123")));
assertThat(parser.parse("2020-12-02T13:59:58.123"), is(fullParse("2020-12-02T13:59:58.123+0000")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@
"statements": [
"CREATE STREAM INPUT (IGNORED INT) WITH (kafka_topic='test_topic', value_format='JSON');",
"CREATE TABLE AGGREGATE AS SELECT COUNT(1) AS COUNT FROM INPUT WINDOW TUMBLING(SIZE 1 SECOND) GROUP BY ROWKEY;",
"SELECT * FROM AGGREGATE WHERE ROWKEY='10' AND WindowStart='2020-02-23T23:45:12.000+0000';"
"SELECT * FROM AGGREGATE WHERE ROWKEY='10' AND WindowStart='2020-02-23T23:45:12.000';"
],
"inputs": [
{"topic": "test_topic", "timestamp": 1582501512456, "key": "11", "value": {}},
Expand Down