| 1 | // { dg-options "-ffreestanding" } |
| 2 | // { dg-do compile { target c++11 } } |
| 3 | |
| 4 | #include <chrono> |
| 5 | |
| 6 | using namespace std::chrono; |
| 7 | |
| 8 | milliseconds |
| 9 | test_duration() |
| 10 | { |
| 11 | seconds sec{1}; |
| 12 | sec = sec + -sec; |
| 13 | return duration_cast<milliseconds>(sec + microseconds{100}); |
| 14 | } |
| 15 | |
| 16 | struct Clock |
| 17 | { |
| 18 | using rep = long; |
| 19 | using period = std::ratio<1,10>; |
| 20 | using duration = std::chrono::duration<rep, period>; |
| 21 | using time_point = std::chrono::time_point<Clock>; |
| 22 | |
| 23 | static const bool is_steady = true; |
| 24 | |
| 25 | static time_point now() noexcept |
| 26 | { |
| 27 | static time_point tick{duration{0}}; |
| 28 | return tick + tick.time_since_epoch(); |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | Clock::time_point |
| 33 | test_time_point() |
| 34 | { |
| 35 | auto t = Clock::now() + milliseconds{1}; |
| 36 | return time_point_cast<Clock::duration>(t); |
| 37 | } |
| 38 | |
| 39 | #if __cplusplus > 202002L |
| 40 | static_assert( is_clock_v<Clock> ); |
| 41 | |
| 42 | bool |
| 43 | test_calendar() |
| 44 | { |
| 45 | auto t = test_time_point(); |
| 46 | t = clock_cast<Clock>(t); |
| 47 | local_days d{floor<days>(t + 1h + 1min + 1s).time_since_epoch()}; |
| 48 | year_month_day ymd{d}; |
| 49 | weekday w{d}; |
| 50 | return w.ok(); |
| 51 | } |
| 52 | #endif |