rok commented on a change in pull request #10610:
URL: https://github.com/apache/arrow/pull/10610#discussion_r702987433
##########
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:
I think it was just to satisfy the compiler.
##########
File path: cpp/src/arrow/compute/api_scalar.h
##########
@@ -278,6 +279,31 @@ struct ARROW_EXPORT DayOfWeekOptions : public
FunctionOptions {
uint32_t week_start;
};
+/// Used to control timestamp timezone conversion and handling
ambiguous/nonexistent
+/// times.
+struct ARROW_EXPORT AssumeTimezoneOptions : public FunctionOptions {
+ public:
+ /// How to interpret ambiguous local times that can be interpreted as
+ /// multiple instants due to DST shifts.
+ enum Ambiguous { AMBIGUOUS_RAISE, AMBIGUOUS_EARLIEST, AMBIGUOUS_LATEST };
+
+ /// How to handle local times that do not exists due to DST shifts.
+ enum Nonexistent { NONEXISTENT_RAISE, NONEXISTENT_EARLIEST,
NONEXISTENT_LATEST };
+
+ explicit AssumeTimezoneOptions(std::string timezone,
+ Ambiguous ambiguous = AMBIGUOUS_RAISE,
+ Nonexistent nonexistent = NONEXISTENT_RAISE);
+ AssumeTimezoneOptions();
+ constexpr static char const kTypeName[] = "AssumeTimezoneOptions";
+
+ /// Timezone and timezone name to convert timestamp from
+ std::string timezone;
+ const arrow_vendored::date::time_zone* tz;
Review comment:
Oh. Probably a bad rebase.
--
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]