rok commented on a change in pull request #10647:
URL: https://github.com/apache/arrow/pull/10647#discussion_r670874881
##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -321,6 +322,82 @@ struct Nanosecond {
}
};
+// ----------------------------------------------------------------------
+// Convert timestamps to a string representation with an arbitrary format
+
+template <typename Duration>
+inline std::string get_timestamp(int64_t arg, const StrftimeOptions* options) {
+ auto zt = arrow_vendored::date::zoned_time<Duration>{options->tz,
+
sys_time<Duration>(Duration{arg})};
+ return arrow_vendored::date::format(options->format, zt);
+}
+
+// If source timestamp is timezone naive we do not print timezone info
+inline StrftimeOptions get_options(KernelContext* ctx, const bool
timezone_known) {
+ const StrftimeOptions options = StrftimeState::Get(ctx);
+ if (timezone_known) {
+ return options;
+ }
+
+ std::string new_format = std::move(options.format);
+ for (std::string str : {"%z", "%Z"}) {
+ size_t pos = std::string::npos;
+ while ((pos = new_format.find(str)) != std::string::npos) {
+ new_format.erase(pos, str.length());
+ }
+ }
+ return StrftimeOptions(new_format, options.timezone);
+}
+
+template <typename Duration>
+struct Strftime {
+ static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+ const auto& timezone = GetInputTimezone(in);
+ const StrftimeOptions options = get_options(ctx, !timezone.empty());
+ if (timezone.empty() && options.timezone != "UTC") {
+ return Status::Invalid("Timezone naive timestamp can only be printed in
UTC. Got: ",
Review comment:
Removed `options.timezone` so this logic was removed.
--
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]