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 // class year_month_weekday;
13
14 // constexpr operator sys_days() const noexcept;
15 //
16 // Returns: If y_.ok() && m_.ok() && wdi_.weekday().ok(), returns a
17 // sys_days that represents the date (index() - 1) * 7 days after the first
18 // weekday() of year()/month(). If index() is 0 the returned sys_days
19 // represents the date 7 days prior to the first weekday() of
20 // year()/month(). Otherwise the returned value is unspecified.
21 //
22
23 #include <chrono>
24 #include <type_traits>
25 #include <cassert>
26
27 #include "test_macros.h"
28
main()29 int main()
30 {
31 using year = std::chrono::year;
32 using month = std::chrono::month;
33 using weekday_indexed = std::chrono::weekday_indexed;
34 using sys_days = std::chrono::sys_days;
35 using days = std::chrono::days;
36 using year_month_weekday = std::chrono::year_month_weekday;
37
38 ASSERT_NOEXCEPT(sys_days(std::declval<year_month_weekday>()));
39
40 {
41 constexpr year_month_weekday ymwd{year{1970}, month{1}, weekday_indexed{std::chrono::Thursday, 1}};
42 constexpr sys_days sd{ymwd};
43
44 static_assert( sd.time_since_epoch() == days{0}, "");
45 static_assert( year_month_weekday{sd} == ymwd, ""); // and back
46 }
47
48 {
49 constexpr year_month_weekday ymwd{year{2000}, month{2}, weekday_indexed{std::chrono::Wednesday, 1}};
50 constexpr sys_days sd{ymwd};
51
52 static_assert( sd.time_since_epoch() == days{10957+32}, "");
53 static_assert( year_month_weekday{sd} == ymwd, ""); // and back
54 }
55
56 // There's one more leap day between 1/1/40 and 1/1/70
57 // when compared to 1/1/70 -> 1/1/2000
58 {
59 constexpr year_month_weekday ymwd{year{1940}, month{1},weekday_indexed{std::chrono::Tuesday, 1}};
60 constexpr sys_days sd{ymwd};
61
62 static_assert( sd.time_since_epoch() == days{-10957}, "");
63 static_assert( year_month_weekday{sd} == ymwd, ""); // and back
64 }
65
66 {
67 year_month_weekday ymwd{year{1939}, month{11}, weekday_indexed{std::chrono::Wednesday, 5}};
68 sys_days sd{ymwd};
69
70 assert( sd.time_since_epoch() == days{-(10957+34)});
71 assert( year_month_weekday{sd} == ymwd); // and back
72 }
73
74 }
75