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 bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
14 //   Returns: x.year() == y.year() && x.month() == y.month().
15 //
16 // constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept;
17 //   Returns:
18 //      If x.year() < y.year() returns true.
19 //      Otherwise, if x.year() > y.year() returns false.
20 //      Otherwise, if x.month() < y.month() returns true.
21 //      Otherwise, if x.month() > y.month() returns false.
22 //      Otherwise, returns x.day() < y.day()
23 
24 
25 #include <chrono>
26 #include <type_traits>
27 #include <cassert>
28 
29 #include "test_macros.h"
30 #include "test_comparisons.h"
31 
main(int,char **)32 int main(int, char**)
33 {
34     using day        = std::chrono::day;
35     using year       = std::chrono::year;
36     using month      = std::chrono::month;
37     using year_month_day = std::chrono::year_month_day;
38 
39     AssertComparisons6AreNoexcept<year_month_day>();
40     AssertComparisons6ReturnBool<year_month_day>();
41 
42     constexpr month January = std::chrono::January;
43     constexpr month February = std::chrono::February;
44 
45     static_assert( testComparisons6(
46         year_month_day{year{1234}, January, day{1}},
47         year_month_day{year{1234}, January, day{1}},
48         true, false), "");
49 
50 //  different day
51     static_assert( testComparisons6(
52         year_month_day{year{1234}, January, day{1}},
53         year_month_day{year{1234}, January, day{2}},
54         false, true), "");
55 
56 //  different month
57     static_assert( testComparisons6(
58         year_month_day{year{1234}, January, day{1}},
59         year_month_day{year{1234}, February, day{1}},
60         false, true), "");
61 
62 //  different year
63     static_assert( testComparisons6(
64         year_month_day{year{1234}, January, day{1}},
65         year_month_day{year{1235}, January, day{1}},
66         false, true), "");
67 
68 
69 //  different month and day
70     static_assert( testComparisons6(
71         year_month_day{year{1234}, January, day{2}},
72         year_month_day{year{1234}, February, day{1}},
73         false, true), "");
74 
75 //  different year and month
76     static_assert( testComparisons6(
77         year_month_day{year{1234}, February, day{1}},
78         year_month_day{year{1235}, January, day{1}},
79         false, true), "");
80 
81 //  different year and day
82     static_assert( testComparisons6(
83         year_month_day{year{1234}, January, day{2}},
84         year_month_day{year{1235}, January, day{1}},
85         false, true), "");
86 
87 //  different year, month and day
88     static_assert( testComparisons6(
89         year_month_day{year{1234}, February, day{2}},
90         year_month_day{year{1235}, January, day{1}},
91         false, true), "");
92 
93 
94 //  same year, different days
95     for (unsigned i = 1; i < 28; ++i)
96         for (unsigned j = 1; j < 28; ++j)
97             assert((testComparisons6(
98                 year_month_day{year{1234}, January, day{i}},
99                 year_month_day{year{1234}, January, day{j}},
100                 i == j, i < j )));
101 
102 //  same year, different months
103     for (unsigned i = 1; i < 12; ++i)
104         for (unsigned j = 1; j < 12; ++j)
105             assert((testComparisons6(
106                 year_month_day{year{1234}, month{i}, day{12}},
107                 year_month_day{year{1234}, month{j}, day{12}},
108                 i == j, i < j )));
109 
110 //  same month, different years
111     for (int i = 1000; i < 20; ++i)
112         for (int j = 1000; j < 20; ++j)
113         assert((testComparisons6(
114             year_month_day{year{i}, January, day{12}},
115             year_month_day{year{j}, January, day{12}},
116             i == j, i < j )));
117 
118   return 0;
119 }
120