@@ -527,14 +527,13 @@ t_tscalar hour_of_day<DTYPE_TIME>(t_tscalar x) {
527527 // Convert the timestamp to a `sys_time` (alias for `time_point`)
528528 date::sys_time<std::chrono::milliseconds> ts (timestamp);
529529
530- // Create a copy of the timestamp with day precision
531- date::sys_days days = date::floor<date::days>(ts);
532-
533- // Subtract the day-precision `time_point` from the datetime-precision one
534- auto time_of_day = date::make_time (ts - days);
530+ // Use localtime so that the hour of day is consistent with all output
531+ // datetimes, which are in local time
532+ std::time_t temp = std::chrono::system_clock::to_time_t (ts);
533+ std::tm* t = std::localtime (&temp);
535534
536- // Get the hour from the resulting `time_point `
537- rval.set (static_cast <std::int64_t >(time_of_day. hours (). count () ));
535+ // Get the hour from the resulting `std::tm `
536+ rval.set (static_cast <std::int64_t >(t-> tm_hour ));
538537 return rval;
539538}
540539
@@ -831,14 +830,14 @@ void day_of_week<DTYPE_TIME>(
831830 // Convert the timestamp to a `sys_time` (alias for `time_point`)
832831 date::sys_time<std::chrono::milliseconds> ts (timestamp);
833832
834- // Create a copy of the timestamp with day precision
835- auto days = date::floor<date::days>(ts);
836-
837- // Find the weekday and write it to the output column
838- auto weekday = date::year_month_weekday (days).weekday_indexed ().weekday ();
833+ // Use localtime so that the hour of day is consistent with all output
834+ // datetimes, which are in local time
835+ std::time_t temp = std::chrono::system_clock::to_time_t (ts);
836+ std::tm* t = std::localtime (&temp);
839837
838+ // Get the weekday from the resulting `std::tm`
840839 output_column->set_nth (
841- idx, days_of_week[(weekday - date::Sunday). count () ]);
840+ idx, days_of_week[t-> tm_wday ]);
842841}
843842
844843template <>
@@ -871,18 +870,16 @@ void month_of_year<DTYPE_TIME>(
871870 // Convert the timestamp to a `sys_time` (alias for `time_point`)
872871 date::sys_time<std::chrono::milliseconds> ts (timestamp);
873872
874- // Create a copy of the timestamp with day precision
875- auto days = date::floor<date::days>(ts);
876-
877- // Cast the `time_point` to contain year/month/day
878- auto ymd = date::year_month_day (days);
873+ // Use localtime so that the hour of day is consistent with all output
874+ // datetimes, which are in local time
875+ std::time_t temp = std::chrono::system_clock::to_time_t (ts);
876+ std::tm* t = std::localtime (&temp);
879877
880- // Get the month as an integer from 0 to 11
881- auto month = (ymd. month () - date::January). count () ;
878+ // Get the month from the resulting `std::tm`
879+ auto month = t-> tm_mon ;
882880
883881 // Get the month string and write into the output column
884- std::string month_of_year = months_of_year[month];
885- output_column->set_nth (idx, month_of_year);
882+ output_column->set_nth (idx, months_of_year[month]);
886883}
887884
888885} // end namespace computed_function
0 commit comments