Skip to content

Commit

Permalink
Define epoch_type
Browse files Browse the repository at this point in the history
  • Loading branch information
mdianjun committed Sep 30, 2024
1 parent 2e050d2 commit 94e97d5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 306 deletions.
1 change: 1 addition & 0 deletions cpp/src/arrow/compute/kernels/scalar_temporal_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ DECLARE_TEMPORAL_BENCHMARKS_ZONED(IsDaylightSavings);
DECLARE_TEMPORAL_BENCHMARKS(PGYear);
DECLARE_TEMPORAL_BENCHMARKS(PGMonth);
DECLARE_TEMPORAL_BENCHMARKS(PGDay);
DECLARE_TEMPORAL_BENCHMARKS(PGWeek);
DECLARE_TEMPORAL_BENCHMARKS(USYear);
DECLARE_TEMPORAL_BENCHMARKS(ISOYear);
DECLARE_TEMPORAL_BENCHMARKS(ISOWeek);
Expand Down
17 changes: 10 additions & 7 deletions cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ using arrow_vendored::date::weekday;
using arrow_vendored::date::weeks;
using arrow_vendored::date::year;
using arrow_vendored::date::year_month_day;
using arrow_vendored::date::year_month_day_pg;
using arrow_vendored::date::year_month_weekday;
using arrow_vendored::date::years;
using arrow_vendored::date::zoned_time;
Expand Down Expand Up @@ -467,7 +466,7 @@ struct USYear {
// ----------------------------------------------------------------------
// Extract PostgreSQL year from temporal types
//
// This class is the same as Year except using year_month_day_pg.
// This class is the same as Year except using pg_epoch.

template <typename Duration, typename Localizer>
struct PGYear {
Expand All @@ -477,8 +476,8 @@ struct PGYear {
template <typename T, typename Arg0>
T Call(KernelContext*, Arg0 arg, Status*) const {
return static_cast<T>(static_cast<const int32_t>(
year_month_day_pg(
floor<days>(localizer_.template ConvertTimePoint<Duration>(arg)))
year_month_day(
floor<days>(localizer_.template ConvertTimePoint<Duration>(arg)), epoch_type::pg_epoch)
.year()));
}

Expand All @@ -496,7 +495,9 @@ struct PGMonth {
template <typename T, typename Arg0>
T Call(KernelContext*, Arg0 arg, Status*) const {
return static_cast<T>(static_cast<const uint32_t>(
year_month_day_pg(floor<days>(localizer_.template ConvertTimePoint<Duration>(arg)))
year_month_day(
floor<days>(localizer_.template ConvertTimePoint<Duration>(arg)),
epoch_type::pg_epoch)
.month()));
}

Expand All @@ -514,7 +515,9 @@ struct PGDay {
template <typename T, typename Arg0>
T Call(KernelContext*, Arg0 arg, Status*) const {
return static_cast<T>(static_cast<const uint32_t>(
year_month_day_pg(floor<days>(localizer_.template ConvertTimePoint<Duration>(arg)))
year_month_day(
floor<days>(localizer_.template ConvertTimePoint<Duration>(arg)),
epoch_type::pg_epoch)
.day()));
}

Expand Down Expand Up @@ -556,7 +559,7 @@ struct PGWeek {
template <typename T, typename Arg0>
T Call(KernelContext*, Arg0 arg, Status*) const {
const auto t = floor<days>(localizer_.template ConvertTimePoint<Duration>(arg));
auto y = year_month_day_pg{t + days_offset_}.year();
auto y = year_month_day{t + days_offset_, epoch_type::pg_epoch}.year();

if (first_week_is_fully_in_year_) {
auto start = localizer_.ConvertDays(y / jan / wd_[1]);
Expand Down
Loading

0 comments on commit 94e97d5

Please sign in to comment.