• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
10 
11 // <chrono>
12 
13 // template<class Duration>
14 //   using sys_time  = time_point<system_clock, Duration>;
15 // using sys_seconds = sys_time<seconds>;
16 // using sys_days    = sys_time<days>;
17 
18 // [Example:
19 //   sys_seconds{sys_days{1970y/January/1}}.time_since_epoch() is 0s.
20 //   sys_seconds{sys_days{2000y/January/1}}.time_since_epoch() is 946’684’800s, which is 10’957 * 86’400s.
21 // —end example]
22 
23 
24 #include <chrono>
25 #include <cassert>
26 
27 #include "test_macros.h"
28 
main()29 int main()
30 {
31     using system_clock = std::chrono::system_clock;
32     using year         = std::chrono::year;
33 
34     using seconds = std::chrono::seconds;
35     using minutes = std::chrono::minutes;
36     using days    = std::chrono::days;
37 
38     using sys_seconds = std::chrono::sys_seconds;
39     using sys_minutes = std::chrono::sys_time<minutes>;
40     using sys_days    = std::chrono::sys_days;
41 
42     constexpr std::chrono::month January = std::chrono::January;
43 
44     ASSERT_SAME_TYPE(std::chrono::sys_time<seconds>, sys_seconds);
45     ASSERT_SAME_TYPE(std::chrono::sys_time<days>,    sys_days);
46 
47 //  Test the long form, too
48     ASSERT_SAME_TYPE(std::chrono::time_point<system_clock, seconds>, sys_seconds);
49     ASSERT_SAME_TYPE(std::chrono::time_point<system_clock, minutes>, sys_minutes);
50     ASSERT_SAME_TYPE(std::chrono::time_point<system_clock, days>,    sys_days);
51 
52 //  Test some well known values
53     sys_days d0 = sys_days{year{1970}/January/1};
54     sys_days d1 = sys_days{year{2000}/January/1};
55     ASSERT_SAME_TYPE(decltype(d0.time_since_epoch()), days);
56     assert( d0.time_since_epoch().count() == 0);
57     assert( d1.time_since_epoch().count() == 10957);
58 
59     sys_seconds s0{d0};
60     sys_seconds s1{d1};
61     ASSERT_SAME_TYPE(decltype(s0.time_since_epoch()), seconds);
62     assert( s0.time_since_epoch().count() == 0);
63     assert( s1.time_since_epoch().count() == 946684800L);
64 }
65