std::chrono::year_month_day represents a calendar date as a year, month, and day. Its whole-value components help the compiler catch swapped or incorrectly typed arguments early. section 4.1
Create New Year's Eve
auto new_years_eve = 2022y / December / 31; creates a readable date using chrono literals and operator/. The explicit form year_month_day(year(2022), month(12), day(31)) expresses the same values. section 4.2.3
Use year_month_day with time points when a calendar date must participate in a time calculation:
- Convert it to a day-based system time with sys_days before subtracting it from another time point. section 4.1
- Floor the current time point to days before extracting its year, preserving the calendar-date boundary. section 4.2.5
- Read the year, month, and day fields through the type's accessors. section 4.5
std::chrono::time_point now = std::chrono::system_clock::now();
Pair the current system_clock time point with a constructed date to build a countdown to a calendar event. section 4.1
