Path: blob/main/contrib/llvm-project/libcxx/include/__chrono/leap_second.h
35262 views
// -*- C++ -*-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-exception6//7//===----------------------------------------------------------------------===//89// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html1011#ifndef _LIBCPP___CHRONO_LEAP_SECOND_H12#define _LIBCPP___CHRONO_LEAP_SECOND_H1314#include <version>15// Enable the contents of the header only when libc++ was built with experimental features enabled.16#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)1718# include <__chrono/duration.h>19# include <__chrono/system_clock.h>20# include <__chrono/time_point.h>21# include <__compare/ordering.h>22# include <__compare/three_way_comparable.h>23# include <__config>24# include <__utility/private_constructor_tag.h>2526# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)27# pragma GCC system_header28# endif2930_LIBCPP_BEGIN_NAMESPACE_STD3132# if _LIBCPP_STD_VER >= 203334namespace chrono {3536class leap_second {37public:38[[nodiscard]]39_LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__private_constructor_tag, sys_seconds __date, seconds __value)40: __date_(__date), __value_(__value) {}4142_LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&) = default;43_LIBCPP_HIDE_FROM_ABI leap_second& operator=(const leap_second&) = default;4445_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; }4647_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; }4849private:50sys_seconds __date_;51seconds __value_;52};5354_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const leap_second& __x, const leap_second& __y) {55return __x.date() == __y.date();56}5758_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) {59return __x.date() <=> __y.date();60}6162template <class _Duration>63_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) {64return __x.date() == __y;65}6667template <class _Duration>68_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) {69return __x.date() < __y;70}7172template <class _Duration>73_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) {74return __x < __y.date();75}7677template <class _Duration>78_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) {79return __y < __x;80}8182template <class _Duration>83_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) {84return __y < __x;85}8687template <class _Duration>88_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) {89return !(__y < __x);90}9192template <class _Duration>93_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) {94return !(__y < __x);95}9697template <class _Duration>98_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) {99return !(__x < __y);100}101102template <class _Duration>103_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) {104return !(__x < __y);105}106107# ifndef _LIBCPP_COMPILER_GCC108// This requirement cause a compilation loop in GCC-13 and running out of memory.109// TODO TZDB Test whether GCC-14 fixes this.110template <class _Duration>111requires three_way_comparable_with<sys_seconds, sys_time<_Duration>>112_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) {113return __x.date() <=> __y;114}115# endif116117} // namespace chrono118119# endif //_LIBCPP_STD_VER >= 20120121_LIBCPP_END_NAMESPACE_STD122123#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)124125#endif // _LIBCPP___CHRONO_LEAP_SECOND_H126127128