2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html
12 #ifndef _LIBCPP___CHRONO_LEAP_SECOND_H
13 #define _LIBCPP___CHRONO_LEAP_SECOND_H
16 // Enable the contents of the header only when libc++ was built with experimental features enabled.
17 #if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
19 # include <__chrono/duration.h>
20 # include <__chrono/system_clock.h>
21 # include <__chrono/time_point.h>
22 # include <__compare/ordering.h>
23 # include <__compare/three_way_comparable.h>
25 # include <__utility/private_constructor_tag.h>
27 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
28 # pragma GCC system_header
31 _LIBCPP_BEGIN_NAMESPACE_STD
33 # if _LIBCPP_STD_VER >= 20
40 _LIBCPP_HIDE_FROM_ABI
explicit constexpr leap_second(__private_constructor_tag
, sys_seconds __date
, seconds __value
)
41 : __date_(__date
), __value_(__value
) {}
43 _LIBCPP_HIDE_FROM_ABI
leap_second(const leap_second
&) = default;
44 _LIBCPP_HIDE_FROM_ABI leap_second
& operator=(const leap_second
&) = default;
46 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr sys_seconds
date() const noexcept
{ return __date_
; }
48 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr seconds
value() const noexcept
{ return __value_
; }
55 // template<class Duration>
56 // requires three_way_comparable_with<sys_seconds, sys_time<Duration>>
57 // constexpr auto operator<=>(const leap_second& x, const sys_time<Duration>& y) noexcept;
59 // Has constraints that are recursive (LWG4139). The proposed resolution is
60 // to make the funcion a hidden friend. For consistency make this change for
61 // all comparison functions.
63 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator==(const leap_second
& __x
, const leap_second
& __y
) {
64 return __x
.date() == __y
.date();
67 _LIBCPP_HIDE_FROM_ABI
friend constexpr strong_ordering
operator<=>(const leap_second
& __x
, const leap_second
& __y
) {
68 return __x
.date() <=> __y
.date();
71 template <class _Duration
>
72 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator==(const leap_second
& __x
, const sys_time
<_Duration
>& __y
) {
73 return __x
.date() == __y
;
76 template <class _Duration
>
77 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<(const leap_second
& __x
, const sys_time
<_Duration
>& __y
) {
78 return __x
.date() < __y
;
81 template <class _Duration
>
82 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<(const sys_time
<_Duration
>& __x
, const leap_second
& __y
) {
83 return __x
< __y
.date();
86 template <class _Duration
>
87 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>(const leap_second
& __x
, const sys_time
<_Duration
>& __y
) {
91 template <class _Duration
>
92 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>(const sys_time
<_Duration
>& __x
, const leap_second
& __y
) {
96 template <class _Duration
>
97 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<=(const leap_second
& __x
, const sys_time
<_Duration
>& __y
) {
101 template <class _Duration
>
102 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator<=(const sys_time
<_Duration
>& __x
, const leap_second
& __y
) {
106 template <class _Duration
>
107 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>=(const leap_second
& __x
, const sys_time
<_Duration
>& __y
) {
111 template <class _Duration
>
112 _LIBCPP_HIDE_FROM_ABI
friend constexpr bool operator>=(const sys_time
<_Duration
>& __x
, const leap_second
& __y
) {
116 template <class _Duration
>
117 requires three_way_comparable_with
<sys_seconds
, sys_time
<_Duration
>>
118 _LIBCPP_HIDE_FROM_ABI
friend constexpr auto operator<=>(const leap_second
& __x
, const sys_time
<_Duration
>& __y
) {
119 return __x
.date() <=> __y
;
123 } // namespace chrono
125 # endif // _LIBCPP_STD_VER >= 20
127 _LIBCPP_END_NAMESPACE_STD
129 #endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
131 #endif // _LIBCPP___CHRONO_LEAP_SECOND_H