|Trying to add 1 month to today does not yield a sys_days!!! [...] next_month's type is time_point<system_clock, duration<int, ratio<54>>|
is the type used to represent the sum of n days
and m months
is a count of ticks in units of p/q
seconds. For std::chrono::days
, the unit p/q
is 86400 seconds. 86400 seconds = 1 day. For months
it's 2629746 seconds = 1 month.
Those numbers come from the definition of days
using days = duration<int, std::ratio<86400>>;
using months = duration<int, std::ratio<2629746>>;
Using those numbers the relevant sum is:
n day + m month = n * 86400sec + m * 2629746sec
To evaluate it and store the result in a duration
we need to choose just one unit p/q
that is known at compile-time.
To do it, the compiler finds gcd(86400, 2629746) = 54
at compile time and factors each term:
54n * 1600sec + 54m * 48699sec = (1600n + 48699m) * 54sec
This says the duration that holds the sum should store (1600n + 48699m)
"almost-minutes" where each "almost-minute" is 54 seconds long.
|can't I cast to duration<days>? |
Since these durations are stored in time_point
s, use time_point_cast