ShivanshhhG commented on code in PR #54684:
URL: https://github.com/apache/arrow/pull/54684#discussion_r4439431209


##########
cpp/src/arrow/compute/kernels/scalar_cast_string.cc:
##########
@@ -200,13 +200,51 @@ struct TemporalToStringCastFunctor<O, TimestampType> {
     DCHECK(!timezone.empty());
     ARROW_ASSIGN_OR_RAISE(auto tz, LocateZone(timezone));
     ARROW_ASSIGN_OR_RAISE(auto locale, GetLocale("C"));
-    TimestampFormatter<Duration> formatter{
-        timezone == "UTC" ? kUtcFormatString : kFormatString, tz, locale};
+    if (timezone == "UTC") {
+      TimestampFormatter<Duration> formatter{kUtcFormatString, tz, locale};
+      return VisitArraySpanInline<TimestampType>(
+          input,
+          [&](value_type v) {
+            ARROW_ASSIGN_OR_RAISE(auto formatted, formatter(v));
+            return builder->Append(std::move(formatted));
+          },
+          [&]() {
+            builder->UnsafeAppendNull();
+            return Status::OK();
+          });
+    }
+
+    ARROW_ASSIGN_OR_RAISE(auto utc_tz, LocateZone("UTC"));
+    TimestampFormatter<Duration> utc_formatter{kUtcFormatString, utc_tz, 
locale};
+    std::ostringstream bufstream;
+    bufstream.imbue(locale);
+    bufstream.exceptions(std::ios::failbit | std::ios::badbit);
+
     return VisitArraySpanInline<TimestampType>(
         input,
         [&](value_type v) {
-          ARROW_ASSIGN_OR_RAISE(auto formatted, formatter(v));
-          return builder->Append(std::move(formatted));
+          bufstream.str("");
+          const auto timepoint = sys_time<Duration>(Duration{v});
+          bool subminute_offset = false;
+          auto format_zoned_time = [&](auto&& zt) {
+            if (ARROW_PREDICT_FALSE(zt.get_info().offset.count() % 60 != 0)) {

Review Comment:
   Good catch, thanks! I updated `ConvertZoned` to branch on `OffsetZone` (and 
`UTC`) upfront so fixed-offset zones take the fast path and avoid the extra 
`get_info()` call and allocation entirely.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to