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