2020#include < gtest/gtest.h>
2121
2222#include " arrow/compute/api_scalar.h"
23+ #include " arrow/util/chrono_internal.h" // for ARROW_USE_STD_CHRONO
24+ #if ARROW_USE_STD_CHRONO
25+ #warning "scalar_temporal_test.cc: Using std::chrono (ARROW_USE_STD_CHRONO=1)"
26+ #else
27+ #warning "scalar_temporal_test.cc: Using date.h (ARROW_USE_STD_CHRONO=0)"
28+ #endif
2329#include " arrow/compute/cast.h"
2430#include " arrow/compute/kernels/test_util_internal.h"
2531#include " arrow/testing/gtest_util.h"
@@ -869,7 +875,13 @@ TEST_F(ScalarTemporalTest, TestZoned2) {
869875 {"iso_year": 2009, "iso_week": 1, "iso_day_of_week": 1},
870876 {"iso_year": 2011, "iso_week": 52, "iso_day_of_week": 7}, null])" );
871877 auto quarter = " [1, 1, 1, 2, 1, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 1, null]" ;
872- auto hour = " [9, 9, 9, 13, 11, 12, 13, 14, 15, 17, 18, 19, 20, 10, 10, 11, null]" ;
878+ // Note: GCC behaves differently for Australia/Broken_Hill around the year 2000 zone
879+ // rule transition. The expected hour for 2000-02-29 (index 1) differs because the
880+ // offset is wrong (+9:30 instead of +10:30).
881+ std::string hour = " [9, 9, 9, 13, 11, 12, 13, 14, 15, 17, 18, 19, 20, 10, 10, 11, null]" ;
882+ #if ARROW_USE_STD_CHRONO
883+ hour.replace (hour.find (" [9, 9, " ), 6 , " [9, 8, " );
884+ #endif
873885 auto minute = " [30, 53, 59, 3, 35, 40, 45, 50, 55, 0, 5, 10, 15, 30, 30, 32, null]" ;
874886
875887 CheckScalarUnary (" year" , unit, times_seconds_precision, int64 (), year);
@@ -890,7 +902,7 @@ TEST_F(ScalarTemporalTest, TestZoned2) {
890902 CheckScalarUnary (" iso_calendar" , ArrayFromJSON (unit, times_seconds_precision),
891903 iso_calendar);
892904 CheckScalarUnary (" quarter" , unit, times_seconds_precision, int64 (), quarter);
893- CheckScalarUnary (" hour" , unit, times_seconds_precision, int64 (), hour);
905+ CheckScalarUnary (" hour" , unit, times_seconds_precision, int64 (), hour. c_str () );
894906 CheckScalarUnary (" minute" , unit, times_seconds_precision, int64 (), minute);
895907 CheckScalarUnary (" second" , unit, times_seconds_precision, int64 (), second);
896908 CheckScalarUnary (" millisecond" , unit, times_seconds_precision, int64 (), zeros);
@@ -2817,26 +2829,32 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, CeilZoned) {
28172829 "2020-01-01 01:09:00", "2019-12-31 02:22:00", "2019-12-30 03:22:00", "2009-12-31 04:22:00",
28182830 "2010-01-01 05:35:00", "2010-01-03 06:43:00", "2010-01-04 07:43:00", "2006-01-01 08:43:00",
28192831 "2005-12-31 09:56:00", "2008-12-28 00:09:00", "2008-12-29 00:09:00", "2012-01-01 01:09:00", null])" ;
2820- const char * ceil_15_hour = R"( [
2832+ std::string ceil_15_hour = R"( [
28212833 "1970-01-01 05:30:00", "2000-03-01 04:30:00", "1899-01-01 06:00:00", "2033-05-18 05:30:00",
28222834 "2020-01-01 04:30:00", "2019-12-31 04:30:00", "2019-12-30 04:30:00", "2009-12-31 04:30:00",
28232835 "2010-01-01 19:30:00", "2010-01-03 19:30:00", "2010-01-04 19:30:00", "2006-01-01 19:30:00",
28242836 "2005-12-31 19:30:00", "2008-12-28 04:30:00", "2008-12-29 04:30:00", "2012-01-01 04:30:00", null])" ;
2825- const char * ceil_15_day = R"( [
2837+ std::string ceil_15_day = R"( [
28262838 "1970-01-15 14:30:00", "2000-03-15 13:30:00", "1899-01-15 15:00:00", "2033-05-30 14:30:00",
28272839 "2020-01-15 13:30:00", "2020-01-14 13:30:00", "2019-12-30 13:30:00", "2010-01-14 13:30:00",
28282840 "2010-01-15 13:30:00", "2010-01-15 13:30:00", "2010-01-15 13:30:00", "2006-01-15 13:30:00",
28292841 "2006-01-14 13:30:00", "2008-12-30 13:30:00", "2008-12-30 13:30:00", "2012-01-15 13:30:00", null])" ;
2830- const char * ceil_3_weeks = R"( [
2842+ std::string ceil_3_weeks = R"( [
28312843 "1970-01-18 14:30:00", "2000-03-05 13:30:00", "1899-01-22 15:00:00", "2033-05-29 14:30:00",
28322844 "2020-01-19 13:30:00", "2020-01-19 13:30:00", "2020-01-19 13:30:00", "2010-01-24 13:30:00",
28332845 "2010-01-24 13:30:00", "2010-01-24 13:30:00", "2010-01-24 13:30:00", "2006-01-22 13:30:00",
28342846 "2006-01-22 13:30:00", "2009-01-11 13:30:00", "2009-01-18 13:30:00", "2012-01-22 13:30:00", null])" ;
2835- const char * ceil_3_weeks_sunday = R"( [
2847+ std::string ceil_3_weeks_sunday = R"( [
28362848 "1970-01-24 14:30:00", "2000-03-25 13:30:00", "1899-01-21 15:00:00", "2033-05-28 14:30:00",
28372849 "2020-01-18 13:30:00", "2020-01-18 13:30:00", "2020-01-18 13:30:00", "2010-01-23 13:30:00",
28382850 "2010-01-23 13:30:00", "2010-01-23 13:30:00", "2010-01-23 13:30:00", "2006-01-21 13:30:00",
28392851 "2006-01-21 13:30:00", "2009-01-24 13:30:00", "2009-01-24 13:30:00", "2012-01-21 13:30:00", null])" ;
2852+ #if ARROW_USE_STD_CHRONO
2853+ ceil_15_hour.replace (ceil_15_hour.find (" 2000-03-01 04:30:00" ), 19 , " 2000-03-01 05:30:00" );
2854+ ceil_15_day.replace (ceil_15_day.find (" 2000-03-15 13:30:00" ), 19 , " 2000-03-15 14:30:00" );
2855+ ceil_3_weeks.replace (ceil_3_weeks.find (" 2000-03-05 13:30:00" ), 19 , " 2000-03-05 14:30:00" );
2856+ ceil_3_weeks_sunday.replace (ceil_3_weeks_sunday.find (" 2000-03-25 13:30:00" ), 19 , " 2000-03-25 14:30:00" );
2857+ #endif
28402858 const char * ceil_5_months = R"( [
28412859 "1970-05-31 14:30:00", "2000-05-31 14:30:00", "1899-05-31 14:30:00", "2033-05-31 14:30:00",
28422860 "2020-05-31 14:30:00", "2020-03-31 13:30:00", "2020-03-31 13:30:00", "2010-03-31 13:30:00",
@@ -2861,10 +2879,10 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, CeilZoned) {
28612879 CheckScalarUnary (op, unit, times, unit, ceil_15_millisecond, &round_to_15_milliseconds);
28622880 CheckScalarUnary (op, unit, times, unit, ceil_13_second, &round_to_13_seconds);
28632881 CheckScalarUnary (op, unit, times, unit, ceil_13_minute, &round_to_13_minutes);
2864- CheckScalarUnary (op, unit, times, unit, ceil_15_hour, &round_to_15_hours);
2865- CheckScalarUnary (op, unit, times, unit, ceil_15_day, &round_to_15_days);
2866- CheckScalarUnary (op, unit, times, unit, ceil_3_weeks, &round_to_3_weeks);
2867- CheckScalarUnary (op, unit, times, unit, ceil_3_weeks_sunday, &round_to_3_weeks_sunday);
2882+ CheckScalarUnary (op, unit, times, unit, ceil_15_hour. c_str () , &round_to_15_hours);
2883+ CheckScalarUnary (op, unit, times, unit, ceil_15_day. c_str () , &round_to_15_days);
2884+ CheckScalarUnary (op, unit, times, unit, ceil_3_weeks. c_str () , &round_to_3_weeks);
2885+ CheckScalarUnary (op, unit, times, unit, ceil_3_weeks_sunday. c_str () , &round_to_3_weeks_sunday);
28682886 CheckScalarUnary (op, unit, times, unit, ceil_5_months, &round_to_5_months);
28692887 CheckScalarUnary (op, unit, times, unit, ceil_3_quarters, &round_to_3_quarters);
28702888 CheckScalarUnary (op, unit, times, unit, ceil_15_years, &round_to_15_years);
@@ -3207,26 +3225,32 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, FloorZoned) {
32073225 "2020-01-01 00:56:00", "2019-12-31 02:09:00", "2019-12-30 03:09:00", "2009-12-31 04:09:00",
32083226 "2010-01-01 05:22:00", "2010-01-03 06:30:00", "2010-01-04 07:30:00", "2006-01-01 08:30:00",
32093227 "2005-12-31 09:43:00", "2008-12-27 23:56:00", "2008-12-28 23:56:00", "2012-01-01 00:56:00", null])" ;
3210- const char * floor_15_hour = R"( [
3228+ std::string floor_15_hour = R"( [
32113229 "1969-12-31 14:30:00", "2000-02-29 13:30:00", "1898-12-31 15:00:00", "2033-05-17 14:30:00",
32123230 "2019-12-31 13:30:00", "2019-12-30 13:30:00", "2019-12-29 13:30:00", "2009-12-30 13:30:00",
32133231 "2010-01-01 04:30:00", "2010-01-03 04:30:00", "2010-01-04 04:30:00", "2006-01-01 04:30:00",
32143232 "2005-12-31 04:30:00", "2008-12-27 13:30:00", "2008-12-28 13:30:00", "2011-12-31 13:30:00", null])" ;
3215- const char * floor_15_day = R"( [
3233+ std::string floor_15_day = R"( [
32163234 "1969-12-31 14:30:00", "2000-02-29 13:30:00", "1898-12-31 15:00:00", "2033-05-15 14:30:00",
32173235 "2019-12-31 13:30:00", "2019-12-30 13:30:00", "2019-12-15 13:30:00", "2009-12-30 13:30:00",
32183236 "2009-12-31 13:30:00", "2009-12-31 13:30:00", "2009-12-31 13:30:00", "2005-12-31 13:30:00",
32193237 "2005-12-30 13:30:00", "2008-12-15 13:30:00", "2008-12-15 13:30:00", "2011-12-31 13:30:00", null])" ;
3220- const char * floor_3_weeks = R"( [
3238+ std::string floor_3_weeks = R"( [
32213239 "1969-12-28 14:30:00", "2000-02-13 13:30:00", "1899-01-01 15:00:00", "2033-05-08 14:30:00",
32223240 "2019-12-29 13:30:00", "2019-12-29 13:30:00", "2019-12-29 13:30:00", "2010-01-03 13:30:00",
32233241 "2010-01-03 13:30:00", "2010-01-03 13:30:00", "2010-01-03 13:30:00", "2006-01-01 13:30:00",
32243242 "2006-01-01 13:30:00", "2008-12-21 13:30:00", "2008-12-28 13:30:00", "2012-01-01 13:30:00", null])" ;
3225- const char * floor_3_weeks_sunday = R"( [
3243+ std::string floor_3_weeks_sunday = R"( [
32263244 "1970-01-03 14:30:00", "2000-03-04 13:30:00", "1898-12-31 15:00:00", "2033-05-07 14:30:00",
32273245 "2019-12-28 13:30:00", "2019-12-28 13:30:00", "2019-12-28 13:30:00", "2010-01-02 13:30:00",
32283246 "2010-01-02 13:30:00", "2010-01-02 13:30:00", "2010-01-02 13:30:00", "2005-12-31 13:30:00",
32293247 "2005-12-31 13:30:00", "2009-01-03 13:30:00", "2009-01-03 13:30:00", "2011-12-31 13:30:00", null])" ;
3248+ #if ARROW_USE_STD_CHRONO
3249+ floor_15_hour.replace (floor_15_hour.find (" 2000-02-29 13:30:00" ), 19 , " 2000-02-29 14:30:00" );
3250+ floor_15_day.replace (floor_15_day.find (" 2000-02-29 13:30:00" ), 19 , " 2000-02-29 14:30:00" );
3251+ floor_3_weeks.replace (floor_3_weeks.find (" 2000-02-13 13:30:00" ), 19 , " 2000-02-13 14:30:00" );
3252+ floor_3_weeks_sunday.replace (floor_3_weeks_sunday.find (" 2000-03-04 13:30:00" ), 19 , " 2000-03-04 14:30:00" );
3253+ #endif
32303254 const char * floor_5_months = R"( [
32313255 "1969-12-31 14:30:00", "1999-12-31 13:30:00", "1898-12-31 15:00:00", "2032-12-31 13:30:00",
32323256 "2019-12-31 13:30:00", "2019-10-31 13:30:00", "2019-10-31 13:30:00", "2009-10-31 13:30:00",
@@ -3253,10 +3277,10 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, FloorZoned) {
32533277 &round_to_15_milliseconds);
32543278 CheckScalarUnary (op, unit, times, unit, floor_13_second, &round_to_13_seconds);
32553279 CheckScalarUnary (op, unit, times, unit, floor_13_minute, &round_to_13_minutes);
3256- CheckScalarUnary (op, unit, times, unit, floor_15_hour, &round_to_15_hours);
3257- CheckScalarUnary (op, unit, times, unit, floor_15_day, &round_to_15_days);
3258- CheckScalarUnary (op, unit, times, unit, floor_3_weeks, &round_to_3_weeks);
3259- CheckScalarUnary (op, unit, times, unit, floor_3_weeks_sunday, &round_to_3_weeks_sunday);
3280+ CheckScalarUnary (op, unit, times, unit, floor_15_hour. c_str () , &round_to_15_hours);
3281+ CheckScalarUnary (op, unit, times, unit, floor_15_day. c_str () , &round_to_15_days);
3282+ CheckScalarUnary (op, unit, times, unit, floor_3_weeks. c_str () , &round_to_3_weeks);
3283+ CheckScalarUnary (op, unit, times, unit, floor_3_weeks_sunday. c_str () , &round_to_3_weeks_sunday);
32603284 CheckScalarUnary (op, unit, times, unit, floor_5_months, &round_to_5_months);
32613285 CheckScalarUnary (op, unit, times, unit, floor_3_quarters, &round_to_3_quarters);
32623286 CheckScalarUnary (op, unit, times, unit, floor_15_years, &round_to_15_years);
@@ -3640,26 +3664,32 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, RoundZoned) {
36403664 "2020-01-01 01:09:00", "2019-12-31 02:09:00", "2019-12-30 03:09:00", "2009-12-31 04:22:00",
36413665 "2010-01-01 05:22:00", "2010-01-03 06:30:00", "2010-01-04 07:30:00", "2006-01-01 08:43:00",
36423666 "2005-12-31 09:43:00", "2008-12-27 23:56:00", "2008-12-28 23:56:00", "2012-01-01 00:56:00", null])" ;
3643- const char * round_15_hour = R"( [
3667+ std::string round_15_hour = R"( [
36443668 "1970-01-01 05:30:00", "2000-03-01 04:30:00", "1899-01-01 06:00:00", "2033-05-18 05:30:00",
36453669 "2020-01-01 04:30:00", "2019-12-31 04:30:00", "2019-12-30 04:30:00", "2009-12-31 04:30:00",
36463670 "2010-01-01 04:30:00", "2010-01-03 04:30:00", "2010-01-04 04:30:00", "2006-01-01 04:30:00",
36473671 "2005-12-31 04:30:00", "2008-12-28 04:30:00", "2008-12-29 04:30:00", "2012-01-01 04:30:00", null])" ;
3648- const char * round_15_day = R"( [
3672+ std::string round_15_day = R"( [
36493673 "1969-12-31 14:30:00", "2000-02-29 13:30:00", "1898-12-31 15:00:00", "2033-05-15 14:30:00",
36503674 "2019-12-31 13:30:00", "2019-12-30 13:30:00", "2019-12-30 13:30:00", "2009-12-30 13:30:00",
36513675 "2009-12-31 13:30:00", "2009-12-31 13:30:00", "2009-12-31 13:30:00", "2005-12-31 13:30:00",
36523676 "2005-12-30 13:30:00", "2008-12-30 13:30:00", "2008-12-30 13:30:00", "2011-12-31 13:30:00", null])" ;
3653- const char * round_3_weeks = R"( [
3677+ std::string round_3_weeks = R"( [
36543678 "1969-12-28 14:30:00", "2000-03-05 13:30:00", "1899-01-01 15:00:00", "2033-05-08 14:30:00",
36553679 "2019-12-29 13:30:00", "2019-12-29 13:30:00", "2019-12-29 13:30:00", "2010-01-03 13:30:00",
36563680 "2010-01-03 13:30:00", "2010-01-03 13:30:00", "2010-01-03 13:30:00", "2006-01-01 13:30:00",
36573681 "2006-01-01 13:30:00", "2008-12-21 13:30:00", "2008-12-28 13:30:00", "2012-01-01 13:30:00",null])" ;
3658- const char * round_3_weeks_sunday = R"( [
3682+ std::string round_3_weeks_sunday = R"( [
36593683 "1970-01-03 14:30:00", "2000-03-04 13:30:00", "1898-12-31 15:00:00", "2033-05-28 14:30:00",
36603684 "2019-12-28 13:30:00", "2019-12-28 13:30:00", "2019-12-28 13:30:00", "2010-01-02 13:30:00",
36613685 "2010-01-02 13:30:00", "2010-01-02 13:30:00", "2010-01-02 13:30:00", "2005-12-31 13:30:00",
36623686 "2005-12-31 13:30:00", "2009-01-03 13:30:00", "2009-01-03 13:30:00", "2011-12-31 13:30:00", null])" ;
3687+ #if ARROW_USE_STD_CHRONO
3688+ round_15_hour.replace (round_15_hour.find (" 2000-03-01 04:30:00" ), 19 , " 2000-03-01 05:30:00" );
3689+ round_15_day.replace (round_15_day.find (" 2000-02-29 13:30:00" ), 19 , " 2000-02-29 14:30:00" );
3690+ round_3_weeks.replace (round_3_weeks.find (" 2000-03-05 13:30:00" ), 19 , " 2000-03-05 14:30:00" );
3691+ round_3_weeks_sunday.replace (round_3_weeks_sunday.find (" 2000-03-04 13:30:00" ), 19 , " 2000-03-04 14:30:00" );
3692+ #endif
36633693 const char * round_5_months = R"( [
36643694 "1969-12-31 14:30:00", "1999-12-31 13:30:00", "1898-12-31 15:00:00", "2033-05-31 14:30:00",
36653695 "2019-12-31 13:30:00", "2019-10-31 13:30:00", "2019-10-31 13:30:00", "2009-10-31 13:30:00",
@@ -3686,10 +3716,10 @@ TEST_F(ScalarTemporalTestMultipleSinceGreaterUnit, RoundZoned) {
36863716 &round_to_15_milliseconds);
36873717 CheckScalarUnary (op, unit, times, unit, round_13_second, &round_to_13_seconds);
36883718 CheckScalarUnary (op, unit, times, unit, round_13_minute, &round_to_13_minutes);
3689- CheckScalarUnary (op, unit, times, unit, round_15_hour, &round_to_15_hours);
3690- CheckScalarUnary (op, unit, times, unit, round_15_day, &round_to_15_days);
3691- CheckScalarUnary (op, unit, times, unit, round_3_weeks, &round_to_3_weeks);
3692- CheckScalarUnary (op, unit, times, unit, round_3_weeks_sunday, &round_to_3_weeks_sunday);
3719+ CheckScalarUnary (op, unit, times, unit, round_15_hour. c_str () , &round_to_15_hours);
3720+ CheckScalarUnary (op, unit, times, unit, round_15_day. c_str () , &round_to_15_days);
3721+ CheckScalarUnary (op, unit, times, unit, round_3_weeks. c_str () , &round_to_3_weeks);
3722+ CheckScalarUnary (op, unit, times, unit, round_3_weeks_sunday. c_str () , &round_to_3_weeks_sunday);
36933723 CheckScalarUnary (op, unit, times, unit, round_5_months, &round_to_5_months);
36943724 CheckScalarUnary (op, unit, times, unit, round_3_quarters, &round_to_3_quarters);
36953725 CheckScalarUnary (op, unit, times, unit, round_15_years, &round_to_15_years);
0 commit comments