Debian Codegraph @

libcxx/test/std/time/time.cal/time.cal.ymwd/time.cal.ymwd.members/ctor.sys_days.pass.cpp

raw
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 // class year_month_weekday;
12
13 // constexpr year_month_weekday(const sys_days& dp) noexcept;
14 //
15 // Effects: Constructs an object of type year_month_weekday that corresponds
16 // to the date represented by dp
17 //
18 // Remarks: For any value ymd of type year_month_weekday for which ymd.ok() is true,
19 // ymd == year_month_weekday{sys_days{ymd}} is true.
20 //
21 // constexpr chrono::year year() const noexcept;
22 // constexpr chrono::month month() const noexcept;
23 // constexpr bool ok() const noexcept;
24
25 #include <chrono>
26 #include <type_traits>
27 #include <cassert>
28
29 #include "test_macros.h"
30
31 int main(int, char**)
32 {
33 using year = std::chrono::year;
34 using days = std::chrono::days;
35 using sys_days = std::chrono::sys_days;
36 using weekday_indexed = std::chrono::weekday_indexed;
37 using year_month_weekday = std::chrono::year_month_weekday;
38
39 ASSERT_NOEXCEPT(year_month_weekday{std::declval<const sys_days>()});
40
41 {
42 constexpr sys_days sd{}; // 1-Jan-1970 was a Thursday
43 constexpr year_month_weekday ymwd{sd};
44
45 static_assert( ymwd.ok(), "");
46 static_assert( ymwd.year() == year{1970}, "");
47 static_assert( ymwd.month() == std::chrono::January, "");
48 static_assert( ymwd.weekday() == std::chrono::Thursday, "");
49 static_assert( ymwd.index() == 1, "");
50 static_assert( ymwd.weekday_indexed() == weekday_indexed{std::chrono::Thursday, 1}, "");
51 static_assert( ymwd == year_month_weekday{sys_days{ymwd}}, ""); // round trip
52 }
53
54 {
55 constexpr sys_days sd{days{10957+32}}; // 2-Feb-2000 was a Wednesday
56 constexpr year_month_weekday ymwd{sd};
57
58 static_assert( ymwd.ok(), "");
59 static_assert( ymwd.year() == year{2000}, "");
60 static_assert( ymwd.month() == std::chrono::February, "");
61 static_assert( ymwd.weekday() == std::chrono::Wednesday, "");
62 static_assert( ymwd.index() == 1, "");
63 static_assert( ymwd.weekday_indexed() == weekday_indexed{std::chrono::Wednesday, 1}, "");
64 static_assert( ymwd == year_month_weekday{sys_days{ymwd}}, ""); // round trip
65 }
66
67
68 {
69 constexpr sys_days sd{days{-10957}}; // 2-Jan-1940 was a Tuesday
70 constexpr year_month_weekday ymwd{sd};
71
72 static_assert( ymwd.ok(), "");
73 static_assert( ymwd.year() == year{1940}, "");
74 static_assert( ymwd.month() == std::chrono::January, "");
75 static_assert( ymwd.weekday() == std::chrono::Tuesday, "");
76 static_assert( ymwd.index() == 1, "");
77 static_assert( ymwd.weekday_indexed() == weekday_indexed{std::chrono::Tuesday, 1}, "");
78 static_assert( ymwd == year_month_weekday{sys_days{ymwd}}, ""); // round trip
79 }
80
81 {
82 sys_days sd{days{-(10957+34)}}; // 29-Nov-1939 was a Wednesday
83 year_month_weekday ymwd{sd};
84
85 assert( ymwd.ok());
86 assert( ymwd.year() == year{1939});
87 assert( ymwd.month() == std::chrono::November);
88 assert( ymwd.weekday() == std::chrono::Wednesday);
89 assert( ymwd.index() == 5);
90 assert((ymwd.weekday_indexed() == weekday_indexed{std::chrono::Wednesday, 5}));
91 assert( ymwd == year_month_weekday{sys_days{ymwd}}); // round trip
92 }
93
94 return 0;
95 }