From 5153e945a7cbef0fe5333e2bee546a48f1cf4818 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 5 May 2023 18:23:36 +0200 Subject: [PATCH 1/3] GH-35448: [C++] Fix detection of %z in strptime format --- cpp/src/arrow/compute/kernels/scalar_string_test.cc | 6 ++++++ cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/compute/kernels/scalar_string_test.cc b/cpp/src/arrow/compute/kernels/scalar_string_test.cc index a98b5937327..a175f044843 100644 --- a/cpp/src/arrow/compute/kernels/scalar_string_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_string_test.cc @@ -1900,6 +1900,12 @@ TYPED_TEST(TestStringKernels, StrptimeZoneOffset) { StrptimeOptions options("%m/%d/%Y %z", TimeUnit::MICRO, /*error_is_null=*/true); this->CheckUnary("strptime", input1, timestamp(TimeUnit::MICRO, "UTC"), output1, &options); + + // format without whitespace before %z (GH-35448) + std::string input2 = R"(["2020-05-01T00:00+0100", null, "1900-12-11T00:00-0130"])"; + StrptimeOptions options("%Y-%m-%dT%H:%M%z", TimeUnit::MICRO, /*error_is_null=*/true); + this->CheckUnary("strptime", input2, timestamp(TimeUnit::MICRO, "UTC"), output1, + &options); } TYPED_TEST(TestStringKernels, StrptimeDoesNotProvideDefaultOptions) { diff --git a/cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc b/cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc index 3addaf68630..a88ce389360 100644 --- a/cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc +++ b/cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc @@ -1237,7 +1237,6 @@ const std::string GetZone(const std::string& format) { zone = "UTC"; break; } - cur++; } else { count = 0; } From 79568b14ca6ff1cc5354ace9ac1e88c99500f711 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 5 May 2023 18:41:53 +0200 Subject: [PATCH 2/3] fix test --- cpp/src/arrow/compute/kernels/scalar_string_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/scalar_string_test.cc b/cpp/src/arrow/compute/kernels/scalar_string_test.cc index a175f044843..efed32f1b0f 100644 --- a/cpp/src/arrow/compute/kernels/scalar_string_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_string_test.cc @@ -1903,9 +1903,9 @@ TYPED_TEST(TestStringKernels, StrptimeZoneOffset) { // format without whitespace before %z (GH-35448) std::string input2 = R"(["2020-05-01T00:00+0100", null, "1900-12-11T00:00-0130"])"; - StrptimeOptions options("%Y-%m-%dT%H:%M%z", TimeUnit::MICRO, /*error_is_null=*/true); + StrptimeOptions options2("%Y-%m-%dT%H:%M%z", TimeUnit::MICRO, /*error_is_null=*/true); this->CheckUnary("strptime", input2, timestamp(TimeUnit::MICRO, "UTC"), output1, - &options); + &options2); } TYPED_TEST(TestStringKernels, StrptimeDoesNotProvideDefaultOptions) { From 45711444117f6ed44d53f0d6836a986b8af977cd Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 6 May 2023 09:47:57 +0200 Subject: [PATCH 3/3] rename test variable --- cpp/src/arrow/compute/kernels/scalar_string_test.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cpp/src/arrow/compute/kernels/scalar_string_test.cc b/cpp/src/arrow/compute/kernels/scalar_string_test.cc index efed32f1b0f..4581e6377a7 100644 --- a/cpp/src/arrow/compute/kernels/scalar_string_test.cc +++ b/cpp/src/arrow/compute/kernels/scalar_string_test.cc @@ -1895,16 +1895,16 @@ TYPED_TEST(TestStringKernels, StrptimeZoneOffset) { // N.B. BSD strptime only supports (+/-)HHMM and not the wider range // of values GNU strptime supports. std::string input1 = R"(["5/1/2020 +0100", null, "12/11/1900 -0130"])"; - std::string output1 = + std::string output = R"(["2020-04-30T23:00:00.000000", null, "1900-12-11T01:30:00.000000"])"; - StrptimeOptions options("%m/%d/%Y %z", TimeUnit::MICRO, /*error_is_null=*/true); - this->CheckUnary("strptime", input1, timestamp(TimeUnit::MICRO, "UTC"), output1, - &options); + StrptimeOptions options1("%m/%d/%Y %z", TimeUnit::MICRO, /*error_is_null=*/true); + this->CheckUnary("strptime", input1, timestamp(TimeUnit::MICRO, "UTC"), output, + &options1); // format without whitespace before %z (GH-35448) std::string input2 = R"(["2020-05-01T00:00+0100", null, "1900-12-11T00:00-0130"])"; StrptimeOptions options2("%Y-%m-%dT%H:%M%z", TimeUnit::MICRO, /*error_is_null=*/true); - this->CheckUnary("strptime", input2, timestamp(TimeUnit::MICRO, "UTC"), output1, + this->CheckUnary("strptime", input2, timestamp(TimeUnit::MICRO, "UTC"), output, &options2); }