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_last;
12
13 // constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept;
14 // Returns: x.year() == y.year() && x.month_day_last() == y.month_day_last().
15 //
16 // constexpr bool operator< (const year_month_day_last& x, const year_month_day_last& y) noexcept;
17 // Returns:
18 // If x.year() < y.year(), returns true.
19 // Otherwise, if x.year() > y.year(), returns false.
20 // Otherwise, returns x.month_day_last() < y.month_day_last()
21
22 #include <chrono>
23 #include <type_traits>
24 #include <cassert>
25
26 #include "test_macros.h"
27 #include "test_comparisons.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 month_day_last = std::chrono::month_day_last;
34 using year_month_day_last = std::chrono::year_month_day_last;
35
36 AssertComparisons6AreNoexcept<year_month_day_last>();
37 AssertComparisons6ReturnBool<year_month_day_last>();
38
39 constexpr month January = std::chrono::January;
40 constexpr month February = std::chrono::February;
41
42 static_assert( testComparisons6(
43 year_month_day_last{year{1234}, month_day_last{January}},
44 year_month_day_last{year{1234}, month_day_last{January}},
45 true, false), "");
46
47 // different month
48 static_assert( testComparisons6(
49 year_month_day_last{year{1234}, month_day_last{January}},
50 year_month_day_last{year{1234}, month_day_last{February}},
51 false, true), "");
52
53 // different year
54 static_assert( testComparisons6(
55 year_month_day_last{year{1234}, month_day_last{January}},
56 year_month_day_last{year{1235}, month_day_last{January}},
57 false, true), "");
58
59 // different month
60 static_assert( testComparisons6(
61 year_month_day_last{year{1234}, month_day_last{January}},
62 year_month_day_last{year{1234}, month_day_last{February}},
63 false, true), "");
64
65 // different year and month
66 static_assert( testComparisons6(
67 year_month_day_last{year{1234}, month_day_last{February}},
68 year_month_day_last{year{1235}, month_day_last{January}},
69 false, true), "");
70
71 // same year, different months
72 for (unsigned i = 1; i < 12; ++i)
73 for (unsigned j = 1; j < 12; ++j)
74 assert((testComparisons6(
75 year_month_day_last{year{1234}, month_day_last{month{i}}},
76 year_month_day_last{year{1234}, month_day_last{month{j}}},
77 i == j, i < j )));
78
79 // same month, different years
80 for (int i = 1000; i < 20; ++i)
81 for (int j = 1000; j < 20; ++j)
82 assert((testComparisons6(
83 year_month_day_last{year{i}, month_day_last{January}},
84 year_month_day_last{year{j}, month_day_last{January}},
85 i == j, i < j )));
86
87 return 0;
88 }
89