From 557114d5196be5f890540d65f7c4c993ff76e6f5 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Thu, 7 Apr 2022 09:41:25 -0400 Subject: [PATCH] Fix to_timestamps to support Z for %z format specifier --- cpp/src/strings/convert/convert_datetime.cu | 16 ++++++++++------ cpp/tests/strings/datetime_tests.cpp | 5 +++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cpp/src/strings/convert/convert_datetime.cu b/cpp/src/strings/convert/convert_datetime.cu index fed201cf726..70a6252e9b3 100644 --- a/cpp/src/strings/convert/convert_datetime.cu +++ b/cpp/src/strings/convert/convert_datetime.cu @@ -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 @@ -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; } diff --git a/cpp/tests/strings/datetime_tests.cpp b/cpp/tests/strings/datetime_tests.cpp index eccf518e13d..f273f8f1fa4 100644 --- a/cpp/tests/strings/datetime_tests.cpp +++ b/cpp/tests/strings/datetime_tests.cpp @@ -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 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 is_expected({1, 1, 1, 1, 1}); + cudf::test::fixed_width_column_wrapper is_expected({1, 1, 1, 1, 1, 1}); CUDF_TEST_EXPECT_COLUMNS_EQUAL(*results, is_expected); }