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++98, c++03, c++11, c++14, c++17
9
10 // <chrono>
11 // class year_month_day;
12
13 // constexpr year_month_day(const sys_days& dp) noexcept;
14 //
15 // Effects: Constructs an object of type year_month_day that corresponds
16 // to the date represented by dp.
17 //
18 // Remarks: For any value ymd of type year_month_day for which ymd.ok() is true,
19 // ymd == year_month_day{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
main(int,char **)31 int main(int, char**)
32 {
33 using year = std::chrono::year;
34 using day = std::chrono::day;
35 using sys_days = std::chrono::sys_days;
36 using days = std::chrono::days;
37 using year_month_day = std::chrono::year_month_day;
38
39 ASSERT_NOEXCEPT(year_month_day{std::declval<sys_days>()});
40
41 {
42 constexpr sys_days sd{};
43 constexpr year_month_day ymd{sd};
44
45 static_assert( ymd.ok(), "");
46 static_assert( ymd.year() == year{1970}, "");
47 static_assert( ymd.month() == std::chrono::January, "");
48 static_assert( ymd.day() == day{1}, "");
49 }
50
51 {
52 constexpr sys_days sd{days{10957+32}};
53 constexpr year_month_day ymd{sd};
54
55 static_assert( ymd.ok(), "");
56 static_assert( ymd.year() == year{2000}, "");
57 static_assert( ymd.month() == std::chrono::February, "");
58 static_assert( ymd.day() == day{2}, "");
59 }
60
61
62 // There's one more leap day between 1/1/40 and 1/1/70
63 // when compared to 1/1/70 -> 1/1/2000
64 {
65 constexpr sys_days sd{days{-10957}};
66 constexpr year_month_day ymd{sd};
67
68 static_assert( ymd.ok(), "");
69 static_assert( ymd.year() == year{1940}, "");
70 static_assert( ymd.month() == std::chrono::January, "");
71 static_assert( ymd.day() == day{2}, "");
72 }
73
74 {
75 sys_days sd{days{-(10957+34)}};
76 year_month_day ymd{sd};
77
78 assert( ymd.ok());
79 assert( ymd.year() == year{1939});
80 assert( ymd.month() == std::chrono::November);
81 assert( ymd.day() == day{29});
82 }
83
84 return 0;
85 }
86