Skip to content

Commit

Permalink
Fix to_timestamps to support Z for %z format specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwendt committed Apr 7, 2022
1 parent fb03c8b commit 557114d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 10 additions & 6 deletions cpp/src/strings/convert/convert_datetime.cu
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,14 @@ struct parse_datetime {
}
case 'z': {
// 'z' format is +hh:mm -- single sign char and 2 chars each for hour and minute
auto const sign = *ptr == '-' ? 1 : -1;
auto const [hh, lh] = parse_int(ptr + 1, 2);
auto const [mm, lm] = parse_int(ptr + 3, 2);
// revert timezone back to UTC
timeparts.tz_minutes = sign * ((hh * 60) + mm);
bytes_read -= lh + lm;
if (item.length == 5) {
auto const sign = *ptr == '-' ? 1 : -1;
auto const [hh, lh] = parse_int(ptr + 1, 2);
auto const [mm, lm] = parse_int(ptr + 3, 2);
// revert timezone back to UTC
timeparts.tz_minutes = sign * ((hh * 60) + mm);
bytes_read -= lh + lm;
}
break;
}
case 'Z': break; // skip
Expand Down Expand Up @@ -574,6 +576,8 @@ struct check_datetime_format {
auto const cvm = check_value(ptr + 3, 2, 0, 59);
result = (*ptr == '-' || *ptr == '+') && cvh.first && cvm.first;
bytes_read -= cvh.second + cvm.second;
} else if (item.length == 1) {
result = *ptr == 'Z';
}
break;
}
Expand Down
5 changes: 3 additions & 2 deletions cpp/tests/strings/datetime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,17 @@ TEST_F(StringsDatetimeTest, ToTimestampTimezone)
"2019-07-17 02:34:56-0300",
"2019-03-20 12:34:56+1030",
"2020-02-29 12:00:00-0500",
"2022-04-07 09:15:00Z",
"1938-11-23 10:28:49+0700"};
auto strings_view = cudf::strings_column_view(strings);
auto results = cudf::strings::to_timestamps(
strings_view, cudf::data_type{cudf::type_id::TIMESTAMP_SECONDS}, "%Y-%m-%d %H:%M:%S%z");
cudf::test::fixed_width_column_wrapper<cudf::timestamp_s, cudf::timestamp_s::rep> expected{
131243025, 1563341696, 1553047496, 1582995600, -981664271};
131243025, 1563341696, 1553047496, 1582995600, 1649322900, -981664271};
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, expected);

results = cudf::strings::is_timestamp(strings_view, "%Y-%m-%d %H:%M:%S%z");
cudf::test::fixed_width_column_wrapper<bool> is_expected({1, 1, 1, 1, 1});
cudf::test::fixed_width_column_wrapper<bool> is_expected({1, 1, 1, 1, 1, 1});
CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, is_expected);
}

Expand Down

0 comments on commit 557114d

Please sign in to comment.