westonpace commented on a change in pull request #10647:
URL: https://github.com/apache/arrow/pull/10647#discussion_r671470682



##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -321,6 +323,68 @@ struct Nanosecond {
   }
 };
 
+// ----------------------------------------------------------------------
+// Convert timestamps to a string representation with an arbitrary format
+
+template <typename Duration>
+inline std::string get_timestamp(int64_t arg, const time_zone* tz,
+                                 const std::string* format) {
+  auto zt =
+      arrow_vendored::date::zoned_time<Duration>{tz, 
sys_time<Duration>(Duration{arg})};
+  return arrow_vendored::date::format(*format, zt);
+}
+
+template <typename Duration>
+struct Strftime {
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    const auto& timezone = GetInputTimezone(in);
+    if (timezone.empty()) {
+      return Status::Invalid("Timezone naive timestamp can not be reliably 
printed.");

Review comment:
       ```suggestion
         return Status::Invalid("Timestamps without a time zone cannot be 
reliably printed.");
   ```
   Nit: We don't formally use "naive" in the docs that I'm aware of as it is a 
python-only concept. 

##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -957,5 +968,17 @@ Result<Datum> Nanosecond(const Datum& values, ExecContext* 
ctx = NULLPTR);
 /// \note API not yet finalized
 ARROW_EXPORT Result<Datum> Subsecond(const Datum& values, ExecContext* ctx = 
NULLPTR);
 
+/// \brief Strftime
+///
+/// \param[in] values input to print time string from
+/// \param[in] options for setting time format and timezone

Review comment:
       ```suggestion
   /// \param[in] options for setting time format
   ```

##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -321,6 +323,68 @@ struct Nanosecond {
   }
 };
 
+// ----------------------------------------------------------------------
+// Convert timestamps to a string representation with an arbitrary format
+
+template <typename Duration>
+inline std::string get_timestamp(int64_t arg, const time_zone* tz,
+                                 const std::string* format) {
+  auto zt =
+      arrow_vendored::date::zoned_time<Duration>{tz, 
sys_time<Duration>(Duration{arg})};
+  return arrow_vendored::date::format(*format, zt);
+}
+
+template <typename Duration>
+struct Strftime {
+  static Status Call(KernelContext* ctx, const Scalar& in, Scalar* out) {
+    const auto& timezone = GetInputTimezone(in);
+    if (timezone.empty()) {
+      return Status::Invalid("Timezone naive timestamp can not be reliably 
printed.");
+    }
+    const arrow_vendored::date::time_zone* tz =
+        arrow_vendored::date::locate_zone(timezone);
+    const StrftimeOptions options = StrftimeState::Get(ctx);
+
+    if (in.is_valid) {
+      const auto& in_val = internal::UnboxScalar<const 
TimestampType>::Unbox(in);
+      *checked_cast<StringScalar*>(out) =
+          StringScalar(get_timestamp<Duration>(in_val, tz, &options.format));
+    } else {
+      out->is_valid = false;
+    }
+    return Status::OK();
+  }
+
+  static Status Call(KernelContext* ctx, const ArrayData& in, ArrayData* out) {
+    const auto& timezone = GetInputTimezone(in);
+    if (timezone.empty()) {
+      return Status::Invalid("Timezone naive timestamp can not be reliably 
printed.");

Review comment:
       ```suggestion
         return Status::Invalid("Timestamp without a time zone cannot be 
reliably printed.");
   ```
   ditto




-- 
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