-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++][chrono] Loads leap-seconds.list in tzdb. #82113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// -*- C++ -*- | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html | ||
|
||
#ifndef _LIBCPP___CHRONO_LEAP_SECOND_H | ||
#define _LIBCPP___CHRONO_LEAP_SECOND_H | ||
|
||
#include <version> | ||
// Enable the contents of the header only when libc++ was built with experimental features enabled. | ||
#if !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB) | ||
|
||
# include <__chrono/duration.h> | ||
# include <__chrono/system_clock.h> | ||
# include <__chrono/time_point.h> | ||
# include <__compare/ordering.h> | ||
# include <__compare/three_way_comparable.h> | ||
# include <__config> | ||
|
||
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
# endif | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
# if _LIBCPP_STD_VER >= 20 | ||
|
||
namespace chrono { | ||
|
||
class leap_second { | ||
public: | ||
struct __constructor_tag; | ||
[[nodiscard]] | ||
_LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__constructor_tag&&, sys_seconds __date, seconds __value) | ||
: __date_(__date), __value_(__value) {} | ||
|
||
_LIBCPP_HIDE_FROM_ABI leap_second(const leap_second&) = default; | ||
_LIBCPP_HIDE_FROM_ABI leap_second& operator=(const leap_second&) = default; | ||
|
||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; } | ||
|
||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr seconds value() const noexcept { return __value_; } | ||
|
||
private: | ||
sys_seconds __date_; | ||
seconds __value_; | ||
}; | ||
|
||
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const leap_second& __x, const leap_second& __y) { | ||
return __x.date() == __y.date(); | ||
} | ||
|
||
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) { | ||
return __x.date() <=> __y.date(); | ||
} | ||
|
||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const leap_second& __x, const sys_time<_Duration>& __y) { | ||
return __x.date() == __y; | ||
} | ||
|
||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const leap_second& __x, const sys_time<_Duration>& __y) { | ||
return __x.date() < __y; | ||
} | ||
|
||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(const sys_time<_Duration>& __x, const leap_second& __y) { | ||
return __x < __y.date(); | ||
} | ||
|
||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const leap_second& __x, const sys_time<_Duration>& __y) { | ||
return __y < __x; | ||
} | ||
|
||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(const sys_time<_Duration>& __x, const leap_second& __y) { | ||
return __y < __x; | ||
} | ||
|
||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const leap_second& __x, const sys_time<_Duration>& __y) { | ||
return !(__y < __x); | ||
} | ||
|
||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(const sys_time<_Duration>& __x, const leap_second& __y) { | ||
return !(__y < __x); | ||
} | ||
|
||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const leap_second& __x, const sys_time<_Duration>& __y) { | ||
return !(__x < __y); | ||
} | ||
|
||
template <class _Duration> | ||
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(const sys_time<_Duration>& __x, const leap_second& __y) { | ||
return !(__x < __y); | ||
} | ||
|
||
# ifndef _LIBCPP_COMPILER_GCC | ||
// This requirement cause a compilation loop in GCC-13 and running out of memory. | ||
// TODO TZDB Test whether GCC-14 fixes this. | ||
template <class _Duration> | ||
requires three_way_comparable_with<sys_seconds, sys_time<_Duration>> | ||
_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(const leap_second& __x, const sys_time<_Duration>& __y) { | ||
return __x.date() <=> __y; | ||
} | ||
# endif | ||
Comment on lines
+108
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GCC trunk now errors on this saying the requirement is depending on itself: https://gcc.godbolt.org/z/aE5jPnnre Can we fix it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not conforming. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
} // namespace chrono | ||
|
||
# endif //_LIBCPP_STD_VER >= 20 | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_TZDB) | ||
|
||
#endif // _LIBCPP___CHRONO_LEAP_SECOND_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// -*- C++ -*- | ||
EricWF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// For information see https://libcxx.llvm.org/DesignDocs/TimeZone.html | ||
|
||
#ifndef _LIBCPP_SRC_INCLUDE_TZDB_LEAP_SECOND_PRIVATE_H | ||
#define _LIBCPP_SRC_INCLUDE_TZDB_LEAP_SECOND_PRIVATE_H | ||
|
||
#include <chrono> | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
namespace chrono { | ||
|
||
struct leap_second::__constructor_tag {}; | ||
|
||
} // namespace chrono | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP_SRC_INCLUDE_TZDB_LEAP_SECOND_PRIVATE_H |
Uh oh!
There was an error while loading. Please reload this page.