| 1 | // { dg-do run { target c++20 } } |
| 2 | |
| 3 | #include <chrono> |
| 4 | #include <testsuite_hooks.h> |
| 5 | |
| 6 | void |
| 7 | test01() |
| 8 | { |
| 9 | using namespace std::chrono; |
| 10 | |
| 11 | gps_seconds gps_epoch{0s}; |
| 12 | utc_seconds gps_as_utc{sys_days{1980y/January/Sunday[1]}.time_since_epoch() + 9s}; |
| 13 | |
| 14 | VERIFY( clock_cast<utc_clock>(gps_epoch) == gps_as_utc ); |
| 15 | VERIFY( gps_epoch == clock_cast<gps_clock>(gps_as_utc) ); |
| 16 | |
| 17 | tai_seconds tai_epoch{0s}; |
| 18 | VERIFY( clock_cast<tai_clock>(clock_cast<gps_clock>(tai_epoch)) == tai_epoch ); |
| 19 | } |
| 20 | |
| 21 | void |
| 22 | test02() |
| 23 | { |
| 24 | using namespace std::chrono; |
| 25 | |
| 26 | sys_days d{2022y/November/12}; |
| 27 | VERIFY( clock_cast<system_clock>(clock_cast<gps_clock>(d)) == d ); |
| 28 | gps_seconds t(1234567s); |
| 29 | VERIFY( clock_cast<gps_clock>(clock_cast<system_clock>(t)) == t ); |
| 30 | VERIFY( clock_cast<gps_clock>(clock_cast<utc_clock>(t)) == t ); |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | test03() |
| 35 | { |
| 36 | using namespace std::chrono; |
| 37 | |
| 38 | gps_time<gps_clock::duration> gps1 = gps_clock::now(); |
| 39 | utc_time<utc_clock::duration> utc = utc_clock::now(); |
| 40 | gps_time<gps_clock::duration> gps2 = gps_clock::now(); |
| 41 | |
| 42 | auto delta = gps2 - gps1; |
| 43 | VERIFY( (utc - clock_cast<utc_clock>(gps1)) <= delta ); |
| 44 | VERIFY( (clock_cast<utc_clock>(gps2) - utc) <= delta ); |
| 45 | |
| 46 | gps_seconds s = time_point_cast<seconds>(gps1); |
| 47 | VERIFY( gps1 - s < 1s ); |
| 48 | } |
| 49 | |
| 50 | int main() |
| 51 | { |
| 52 | test01(); |
| 53 | test02(); |
| 54 | test03(); |
| 55 | } |