@@ -14,22 +14,25 @@ USERVER_NAMESPACE_BEGIN
1414namespace utils ::datetime {
1515
1616// TODO: remove the following aliases
17- namespace date = std::chrono;
1817using Days = std::chrono::days;
1918using DaysTimepoint = std::chrono::sys_days;
2019
2120// / @brief Calculates the number of days between January 1, 00:00 of two years accounting for leap years.
2221constexpr std::chrono::days DaysBetweenYears (int from, int to) {
2322 return std::chrono::duration_cast<Days>(
24- DaysTimepoint{date:: year_month_day (date:: year (to), date:: month (1 ), date ::day (1 ))} -
25- DaysTimepoint{date:: year_month_day (date:: year (from), date:: month (1 ), date ::day (1 ))}
23+ DaysTimepoint{std::chrono:: year_month_day (std::chrono:: year (to), std::chrono:: month (1 ), std::chrono ::day (1 ))} -
24+ DaysTimepoint{std::chrono:: year_month_day (std::chrono:: year (from), std::chrono:: month (1 ), std::chrono ::day (1 ))}
2625 );
2726}
2827
2928// / @brief Get the number of days in the given month of a given year.
3029constexpr std::chrono::day DaysInMonth (int month, int year) {
3130 UINVARIANT (month >= 1 && month <= 12 , " Month must be between 1 and 12" );
32- return date::year_month_day_last (date::year (year), date::month_day_last (date::month (month))).day ();
31+ return std::chrono::year_month_day_last (
32+ std::chrono::year (year),
33+ std::chrono::month_day_last (std::chrono::month (month))
34+ )
35+ .day ();
3336}
3437
3538} // namespace utils::datetime
0 commit comments