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
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-filesystem, no-localization, no-tzdb
11
12 // TODO TZDB investigate why this fails with GCC
13 // UNSUPPORTED: gcc-14
14
15 // XFAIL: libcpp-has-no-experimental-tzdb
16 // XFAIL: availability-tzdb-missing
17
18 // <chrono>
19
20 // class leap_second;
21
22 //constexpr bool operator==(const leap_second& x, const leap_second& y); // C++20
23 //constexpr strong_ordering operator<=>(const leap_second& x, const leap_second& y);
24 //
25 //template<class Duration>
26 // constexpr bool operator==(const leap_second& x, const sys_time<Duration>& y);
27 //template<class Duration>
28 // constexpr bool operator< (const leap_second& x, const sys_time<Duration>& y);
29 //template<class Duration>
30 // constexpr bool operator< (const sys_time<Duration>& x, const leap_second& y);
31 //template<class Duration>
32 // constexpr bool operator> (const leap_second& x, const sys_time<Duration>& y);
33 //template<class Duration>
34 // constexpr bool operator> (const sys_time<Duration>& x, const leap_second& y);
35 //template<class Duration>
36 // constexpr bool operator<=(const leap_second& x, const sys_time<Duration>& y);
37 //template<class Duration>
38 // constexpr bool operator<=(const sys_time<Duration>& x, const leap_second& y);
39 //template<class Duration>
40 // constexpr bool operator>=(const leap_second& x, const sys_time<Duration>& y);
41 //template<class Duration>
42 // constexpr bool operator>=(const sys_time<Duration>& x, const leap_second& y);
43 //template<class Duration>
44 // requires three_way_comparable_with<sys_seconds, sys_time<Duration>>
45 // constexpr auto operator<=>(const leap_second& x, const sys_time<Duration>& y);
46
47 #include <cassert>
48 #include <chrono>
49
50 #include "test_macros.h"
51 #include "test_comparisons.h"
52
53 #include "test_chrono_leap_second.h"
54
test_comparison(const std::chrono::leap_second lhs,const std::chrono::leap_second rhs)55 constexpr void test_comparison(const std::chrono::leap_second lhs, const std::chrono::leap_second rhs) {
56 AssertOrderReturn<std::strong_ordering, std::chrono::leap_second>();
57 assert(testOrder(lhs, rhs, std::strong_ordering::less));
58
59 AssertOrderReturn<std::strong_ordering, std::chrono::leap_second, std::chrono::sys_seconds>();
60 assert(testOrder(lhs, rhs.date(), std::strong_ordering::less));
61
62 AssertOrderReturn<std::strong_ordering, std::chrono::sys_seconds, std::chrono::leap_second>();
63 assert(testOrder(lhs.date(), rhs, std::strong_ordering::less));
64 }
65
test()66 constexpr bool test() {
67 test_comparison(test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1}),
68 test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{1}}, std::chrono::seconds{2}));
69
70 return true;
71 }
72
main(int,const char **)73 int main(int, const char**) {
74 test();
75 static_assert(test());
76
77 // test with the real tzdb
78 const std::chrono::tzdb& tzdb = std::chrono::get_tzdb();
79 assert(tzdb.leap_seconds.size() > 2);
80 test_comparison(tzdb.leap_seconds[0], tzdb.leap_seconds[1]);
81
82 return 0;
83 }
84