| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 9 | |
| 10 | // <chrono> |
| 11 | |
| 12 | // template<class Duration> |
| 13 | // using sys_time = time_point<system_clock, Duration>; |
| 14 | // using sys_seconds = sys_time<seconds>; |
| 15 | // using sys_days = sys_time<days>; |
| 16 | |
| 17 | // [Example: |
| 18 | // sys_seconds{sys_days{1970y/January/1}}.time_since_epoch() is 0s. |
| 19 | // sys_seconds{sys_days{2000y/January/1}}.time_since_epoch() is 946'684'800s, which is 10'957 * 86'400s. |
| 20 | // - end example] |
| 21 | |
| 22 | |
| 23 | #include <chrono> |
| 24 | #include <cassert> |
| 25 | |
| 26 | #include "test_macros.h" |
| 27 | |
| 28 | int main(int, char**) |
| 29 | { |
| 30 | using system_clock = std::chrono::system_clock; |
| 31 | using year = std::chrono::year; |
| 32 | |
| 33 | using seconds = std::chrono::seconds; |
| 34 | using minutes = std::chrono::minutes; |
| 35 | using days = std::chrono::days; |
| 36 | |
| 37 | using sys_seconds = std::chrono::sys_seconds; |
| 38 | using sys_minutes = std::chrono::sys_time<minutes>; |
| 39 | using sys_days = std::chrono::sys_days; |
| 40 | |
| 41 | constexpr std::chrono::month January = std::chrono::January; |
| 42 | |
| 43 | ASSERT_SAME_TYPE(std::chrono::sys_time<seconds>, sys_seconds); |
| 44 | ASSERT_SAME_TYPE(std::chrono::sys_time<days>, sys_days); |
| 45 | |
| 46 | // Test the long form, too |
| 47 | ASSERT_SAME_TYPE(std::chrono::time_point<system_clock, seconds>, sys_seconds); |
| 48 | ASSERT_SAME_TYPE(std::chrono::time_point<system_clock, minutes>, sys_minutes); |
| 49 | ASSERT_SAME_TYPE(std::chrono::time_point<system_clock, days>, sys_days); |
| 50 | |
| 51 | // Test some well known values |
| 52 | sys_days d0 = sys_days{year{1970}/January/1}; |
| 53 | sys_days d1 = sys_days{year{2000}/January/1}; |
| 54 | ASSERT_SAME_TYPE(decltype(d0.time_since_epoch()), days); |
| 55 | assert( d0.time_since_epoch().count() == 0); |
| 56 | assert( d1.time_since_epoch().count() == 10957); |
| 57 | |
| 58 | sys_seconds s0{d0}; |
| 59 | sys_seconds s1{d1}; |
| 60 | ASSERT_SAME_TYPE(decltype(s0.time_since_epoch()), seconds); |
| 61 | assert( s0.time_since_epoch().count() == 0); |
| 62 | assert( s1.time_since_epoch().count() == 946684800L); |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |