xref: /freebsd-src/contrib/llvm-project/libcxx/include/__chrono/leap_second.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1*0fca6ea1SDimitry Andric // -*- C++ -*-
2*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===//
3*0fca6ea1SDimitry Andric //
4*0fca6ea1SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*0fca6ea1SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6*0fca6ea1SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*0fca6ea1SDimitry Andric //
8*0fca6ea1SDimitry Andric //===----------------------------------------------------------------------===//
9*0fca6ea1SDimitry Andric 
10*0fca6ea1SDimitry Andric // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
11*0fca6ea1SDimitry Andric 
12*0fca6ea1SDimitry Andric #ifndef _LIBCPP___CHRONO_LEAP_SECOND_H
13*0fca6ea1SDimitry Andric #define _LIBCPP___CHRONO_LEAP_SECOND_H
14*0fca6ea1SDimitry Andric 
15*0fca6ea1SDimitry Andric #include <version>
16*0fca6ea1SDimitry Andric // Enable the contents of the header only when libc++ was built with experimental features enabled.
17*0fca6ea1SDimitry Andric #if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
18*0fca6ea1SDimitry Andric 
19*0fca6ea1SDimitry Andric #  include <__chrono/duration.h>
20*0fca6ea1SDimitry Andric #  include <__chrono/system_clock.h>
21*0fca6ea1SDimitry Andric #  include <__chrono/time_point.h>
22*0fca6ea1SDimitry Andric #  include <__compare/ordering.h>
23*0fca6ea1SDimitry Andric #  include <__compare/three_way_comparable.h>
24*0fca6ea1SDimitry Andric #  include <__config>
25*0fca6ea1SDimitry Andric #  include <__utility/private_constructor_tag.h>
26*0fca6ea1SDimitry Andric 
27*0fca6ea1SDimitry Andric #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28*0fca6ea1SDimitry Andric #    pragma GCC system_header
29*0fca6ea1SDimitry Andric #  endif
30*0fca6ea1SDimitry Andric 
31*0fca6ea1SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
32*0fca6ea1SDimitry Andric 
33*0fca6ea1SDimitry Andric #  if _LIBCPP_STD_VER >= 20
34*0fca6ea1SDimitry Andric 
35*0fca6ea1SDimitry Andric namespace chrono {
36*0fca6ea1SDimitry Andric 
37*0fca6ea1SDimitry Andric class leap_second {
38*0fca6ea1SDimitry Andric public:
39*0fca6ea1SDimitry Andric   [[nodiscard]]
40*0fca6ea1SDimitry Andric   _LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__private_constructor_tag, sys_seconds __date, seconds __value)
41*0fca6ea1SDimitry Andric       : __date_(__date), __value_(__value) {}
42*0fca6ea1SDimitry Andric 
43*0fca6ea1SDimitry Andric   _LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&)            = default;
44*0fca6ea1SDimitry Andric   _LIBCPP_HIDE_FROM_ABI leap_second& operator=(const leap_second&) = default;
45*0fca6ea1SDimitry Andric 
46*0fca6ea1SDimitry Andric   _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; }
47*0fca6ea1SDimitry Andric 
48*0fca6ea1SDimitry Andric   _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; }
49*0fca6ea1SDimitry Andric 
50*0fca6ea1SDimitry Andric private:
51*0fca6ea1SDimitry Andric   sys_seconds __date_;
52*0fca6ea1SDimitry Andric   seconds __value_;
53*0fca6ea1SDimitry Andric };
54*0fca6ea1SDimitry Andric 
55*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const leap_second& __x, const leap_second& __y) {
56*0fca6ea1SDimitry Andric   return __x.date() == __y.date();
57*0fca6ea1SDimitry Andric }
58*0fca6ea1SDimitry Andric 
59*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) {
60*0fca6ea1SDimitry Andric   return __x.date() <=> __y.date();
61*0fca6ea1SDimitry Andric }
62*0fca6ea1SDimitry Andric 
63*0fca6ea1SDimitry Andric template <class _Duration>
64*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) {
65*0fca6ea1SDimitry Andric   return __x.date() == __y;
66*0fca6ea1SDimitry Andric }
67*0fca6ea1SDimitry Andric 
68*0fca6ea1SDimitry Andric template <class _Duration>
69*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) {
70*0fca6ea1SDimitry Andric   return __x.date() < __y;
71*0fca6ea1SDimitry Andric }
72*0fca6ea1SDimitry Andric 
73*0fca6ea1SDimitry Andric template <class _Duration>
74*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) {
75*0fca6ea1SDimitry Andric   return __x < __y.date();
76*0fca6ea1SDimitry Andric }
77*0fca6ea1SDimitry Andric 
78*0fca6ea1SDimitry Andric template <class _Duration>
79*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) {
80*0fca6ea1SDimitry Andric   return __y < __x;
81*0fca6ea1SDimitry Andric }
82*0fca6ea1SDimitry Andric 
83*0fca6ea1SDimitry Andric template <class _Duration>
84*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) {
85*0fca6ea1SDimitry Andric   return __y < __x;
86*0fca6ea1SDimitry Andric }
87*0fca6ea1SDimitry Andric 
88*0fca6ea1SDimitry Andric template <class _Duration>
89*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) {
90*0fca6ea1SDimitry Andric   return !(__y < __x);
91*0fca6ea1SDimitry Andric }
92*0fca6ea1SDimitry Andric 
93*0fca6ea1SDimitry Andric template <class _Duration>
94*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) {
95*0fca6ea1SDimitry Andric   return !(__y < __x);
96*0fca6ea1SDimitry Andric }
97*0fca6ea1SDimitry Andric 
98*0fca6ea1SDimitry Andric template <class _Duration>
99*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) {
100*0fca6ea1SDimitry Andric   return !(__x < __y);
101*0fca6ea1SDimitry Andric }
102*0fca6ea1SDimitry Andric 
103*0fca6ea1SDimitry Andric template <class _Duration>
104*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) {
105*0fca6ea1SDimitry Andric   return !(__x < __y);
106*0fca6ea1SDimitry Andric }
107*0fca6ea1SDimitry Andric 
108*0fca6ea1SDimitry Andric #    ifndef _LIBCPP_COMPILER_GCC
109*0fca6ea1SDimitry Andric // This requirement cause a compilation loop in GCC-13 and running out of memory.
110*0fca6ea1SDimitry Andric // TODO TZDB Test whether GCC-14 fixes this.
111*0fca6ea1SDimitry Andric template <class _Duration>
112*0fca6ea1SDimitry Andric   requires three_way_comparable_with<sys_seconds, sys_time<_Duration>>
113*0fca6ea1SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) {
114*0fca6ea1SDimitry Andric   return __x.date() <=> __y;
115*0fca6ea1SDimitry Andric }
116*0fca6ea1SDimitry Andric #    endif
117*0fca6ea1SDimitry Andric 
118*0fca6ea1SDimitry Andric } // namespace chrono
119*0fca6ea1SDimitry Andric 
120*0fca6ea1SDimitry Andric #  endif //_LIBCPP_STD_VER >= 20
121*0fca6ea1SDimitry Andric 
122*0fca6ea1SDimitry Andric _LIBCPP_END_NAMESPACE_STD
123*0fca6ea1SDimitry Andric 
124*0fca6ea1SDimitry Andric #endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
125*0fca6ea1SDimitry Andric 
126*0fca6ea1SDimitry Andric #endif // _LIBCPP___CHRONO_LEAP_SECOND_H
127