rok commented on a change in pull request #10610:
URL: https://github.com/apache/arrow/pull/10610#discussion_r703017328



##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal.cc
##########
@@ -571,6 +592,73 @@ struct Strftime {
 };
 #endif
 
+// ----------------------------------------------------------------------
+// Convert timestamps from local timestamp without a timezone to timestamps 
with a
+// timezone, interpreting the local timestamp as being in the specified 
timezone
+
+template <typename Duration>
+struct AssumeTimezone {
+  explicit AssumeTimezone(const AssumeTimezoneOptions* options, const 
time_zone* tz)
+      : options(*options), tz_(tz) {}
+
+  template <typename T, typename Arg0>
+  T get_local_time(Arg0 arg, const time_zone* tz) const {
+    return static_cast<T>(zoned_time<Duration>(tz, 
local_time<Duration>(Duration{arg}))
+                              .get_sys_time()
+                              .time_since_epoch()
+                              .count());
+  }
+
+  template <typename T, typename Arg0>
+  T get_local_time(Arg0 arg, const arrow_vendored::date::choose choose,
+                   const time_zone* tz) const {
+    return static_cast<T>(
+        zoned_time<Duration>(tz, local_time<Duration>(Duration{arg}), choose)
+            .get_sys_time()
+            .time_since_epoch()
+            .count());
+  }
+
+  template <typename T, typename Arg0>
+  T Call(KernelContext*, Arg0 arg, Status* st) const {
+    try {
+      return get_local_time<T, Arg0>(arg, tz_);
+    } catch (const arrow_vendored::date::nonexistent_local_time& e) {
+      switch (options.nonexistent) {
+        case AssumeTimezoneOptions::Nonexistent::NONEXISTENT_RAISE: {
+          *st = Status::Invalid("Nonexistent: ", e.what());
+          return arg;
+        }
+        case AssumeTimezoneOptions::Nonexistent::NONEXISTENT_EARLIEST: {
+          return get_local_time<T, Arg0>(arg, 
arrow_vendored::date::choose::earliest,
+                                         tz_);
+        }
+        case AssumeTimezoneOptions::Nonexistent::NONEXISTENT_LATEST: {
+          return get_local_time<T, Arg0>(arg, 
arrow_vendored::date::choose::latest, tz_);
+        }
+      }
+    } catch (const arrow_vendored::date::ambiguous_local_time& e) {
+      switch (options.ambiguous) {
+        case AssumeTimezoneOptions::Ambiguous::AMBIGUOUS_RAISE: {
+          *st = Status::Invalid("Ambiguous: ", e.what());
+          return arg;
+        }
+        case AssumeTimezoneOptions::Ambiguous::AMBIGUOUS_EARLIEST: {
+          return get_local_time<T, Arg0>(arg, 
arrow_vendored::date::choose::earliest,
+                                         tz_);
+        }
+        case AssumeTimezoneOptions::Ambiguous::AMBIGUOUS_LATEST: {
+          return get_local_time<T, Arg0>(arg, 
arrow_vendored::date::choose::latest, tz_);
+        }
+      }
+    }
+    *st = Status::UnknownError("Unknown error.");

Review comment:
       Removed the status but kept the `return 0` to keep he compiler happy. 
Please check.




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