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_day;
12
13 // constexpr year_month_day(const year_month_day_last& ymdl) noexcept;
14 //
15 // Effects: Constructs an object of type year_month_day by initializing
16 // y_ with ymdl.year(), m_ with ymdl.month(), and d_ with ymdl.day().
17 //
18 // constexpr chrono::year year() const noexcept;
19 // constexpr chrono::month month() const noexcept;
20 // constexpr chrono::day day() const noexcept;
21 // constexpr bool ok() const noexcept;
22
23 #include <chrono>
24 #include <type_traits>
25 #include <cassert>
26
27 #include "test_macros.h"
28
main(int,char **)29 int main(int, char**)
30 {
31 using year = std::chrono::year;
32 using month = std::chrono::month;
33 using day = std::chrono::day;
34 using month_day_last = std::chrono::month_day_last;
35 using year_month_day_last = std::chrono::year_month_day_last;
36 using year_month_day = std::chrono::year_month_day;
37
38 ASSERT_NOEXCEPT(year_month_day{std::declval<const year_month_day_last>()});
39
40 {
41 constexpr year_month_day_last ymdl{year{2019}, month_day_last{month{1}}};
42 constexpr year_month_day ymd{ymdl};
43
44 static_assert( ymd.year() == year{2019}, "");
45 static_assert( ymd.month() == month{1}, "");
46 static_assert( ymd.day() == day{31}, "");
47 static_assert( ymd.ok(), "");
48 }
49
50 {
51 constexpr year_month_day_last ymdl{year{1970}, month_day_last{month{4}}};
52 constexpr year_month_day ymd{ymdl};
53
54 static_assert( ymd.year() == year{1970}, "");
55 static_assert( ymd.month() == month{4}, "");
56 static_assert( ymd.day() == day{30}, "");
57 static_assert( ymd.ok(), "");
58 }
59
60 {
61 constexpr year_month_day_last ymdl{year{2000}, month_day_last{month{2}}};
62 constexpr year_month_day ymd{ymdl};
63
64 static_assert( ymd.year() == year{2000}, "");
65 static_assert( ymd.month() == month{2}, "");
66 static_assert( ymd.day() == day{29}, "");
67 static_assert( ymd.ok(), "");
68 }
69
70 { // Feb 1900 was NOT a leap year.
71 year_month_day_last ymdl{year{1900}, month_day_last{month{2}}};
72 year_month_day ymd{ymdl};
73
74 assert( ymd.year() == year{1900});
75 assert( ymd.month() == month{2});
76 assert( ymd.day() == day{28});
77 assert( ymd.ok());
78 }
79
80 return 0;
81 }
82