mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-05 05:34:27 +02:00
Updated Examples and Recipes (markdown)
@@ -743,22 +743,7 @@ Assuming the birthdate is exactly synchronized with TAI (offset by the timezone)
|
|||||||
auto birthday = to_tai_time(make_zoned(zone,
|
auto birthday = to_tai_time(make_zoned(zone,
|
||||||
local_days{apr/24/1954} + 10h + 3min - 10s).get_sys_time());
|
local_days{apr/24/1954} + 10h + 3min - 10s).get_sys_time());
|
||||||
|
|
||||||
We have to subtract 10s manually because we want the birthday to be `1954-04-24 18:03:00 TAI` and without that 10s subtraction we have UTC modeled back to 1954 instead of modeling TAI in 1954.
|
We have to subtract 10s manually because we want the birthday to be `1954-04-24 18:03:00 TAI` and without that 10s subtraction we have UTC modeled back to 1954 instead of modeling TAI in 1954. Then we add the 2Gs in `tai_time` and convert that result back to `sys_time`, and then to a `zoned_time`:
|
||||||
|
|
||||||
Another way to do this would be to "reinterpret_cast" the `sys_time` to `tai_time`. This would relieve us from having to know about the 10s constant. This is done with the following syntax:
|
|
||||||
|
|
||||||
auto birthday = tai_seconds{make_zoned(zone,
|
|
||||||
local_days{apr/24/1954} + 10h + 3min).get_sys_time().time_since_epoch()};
|
|
||||||
|
|
||||||
Either way, the result is the same. This line:
|
|
||||||
|
|
||||||
std::cout << "born : " << birthday << " TAI \n";
|
|
||||||
|
|
||||||
will output:
|
|
||||||
|
|
||||||
born : 1942-04-24 18:03:00 TAI
|
|
||||||
|
|
||||||
Then we add the 2Gs in `tai_time` and convert that result back to `sys_time`, and then to a `zoned_time`:
|
|
||||||
|
|
||||||
auto Day2Gs = make_zoned(zone, to_sys_time(birthday + 2'000'000'000s));
|
auto Day2Gs = make_zoned(zone, to_sys_time(birthday + 2'000'000'000s));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user