sys_time is a chrono time-point alias based on system_clock. Give it a duration, such as days, to represent an event and subtract it from now to obtain a duration. section 4.1 section 4.1
Countdown to an event
Create New Year's Eve with sys_days, then subtract the current system time: `auto event = std::chrono::sys_days(new_years_eve);` followed by `std::chrono::duration dur = event - now;`. The result can be streamed with C++20 chrono output or inspected with `dur.count()`. section 4.1 section 4.1
Use sys_time when physical elapsed time matters across civil-time changes. Convert local dates through zoned_time and compare their system times; local_time arithmetic intentionally preserves local clock time instead. section 4.4 section 4.4
Listing 4.15 Countdown in local time
std::chrono::system_clock::duration
countdown_in_local_time(std::chrono::system_clock::time_point now,
std::chrono::year_month_day date)
{
using namespace std::chrono;
auto sys_event = zoned_time(current_zone(),
local_days{ date }).get_sys_time(); #1
return sys_event - now; #2
}
A complete countdown function converts a local event through the current time zone, obtains system time, and subtracts now. section 4.4
