Release Cosmopolitan v3.6.0

This release is an atomic upgrade to GCC 14.1.0 with C23 and C++23
This commit is contained in:
Justine Tunney 2024-07-23 03:16:17 -07:00
parent 62ace3623a
commit 5660ec4741
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
1585 changed files with 117353 additions and 271644 deletions

View file

@ -22,19 +22,19 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
struct local_t {};
template<class Duration>
using local_time = time_point<local_t, Duration>;
template <class _Duration>
using local_time = time_point<local_t, _Duration>;
using local_seconds = local_time<seconds>;
using local_days = local_time<days>;
struct last_spec { explicit last_spec() = default; };
struct last_spec {
explicit last_spec() = default;
};
inline constexpr last_spec last{};
} // namespace chrono
_LIBCPP_END_NAMESPACE_STD

View file

@ -26,23 +26,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// Convert a nanoseconds duration to the given TimeSpec type, which must have
// the same properties as std::timespec.
template <class _TimeSpec>
_LIBCPP_HIDE_FROM_ABI inline
_TimeSpec __convert_to_timespec(const chrono::nanoseconds& __ns)
{
_LIBCPP_HIDE_FROM_ABI inline _TimeSpec __convert_to_timespec(const chrono::nanoseconds& __ns) {
using namespace chrono;
seconds __s = duration_cast<seconds>(__ns);
_TimeSpec __ts;
typedef decltype(__ts.tv_sec) __ts_sec;
const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max();
if (__s.count() < __ts_sec_max)
{
__ts.tv_sec = static_cast<__ts_sec>(__s.count());
if (__s.count() < __ts_sec_max) {
__ts.tv_sec = static_cast<__ts_sec>(__s.count());
__ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count());
}
else
{
__ts.tv_sec = __ts_sec_max;
} else {
__ts.tv_sec = __ts_sec_max;
__ts.tv_nsec = 999999999; // (10^9 - 1)
}

View file

@ -16,10 +16,12 @@
#include <__chrono/duration.h>
#include <__chrono/file_clock.h>
#include <__chrono/hh_mm_ss.h>
#include <__chrono/local_info.h>
#include <__chrono/month.h>
#include <__chrono/month_weekday.h>
#include <__chrono/monthday.h>
#include <__chrono/statically_widen.h>
#include <__chrono/sys_info.h>
#include <__chrono/system_clock.h>
#include <__chrono/time_point.h>
#include <__chrono/weekday.h>
@ -27,10 +29,13 @@
#include <__chrono/year_month.h>
#include <__chrono/year_month_day.h>
#include <__chrono/year_month_weekday.h>
#include <__chrono/zoned_time.h>
#include <__concepts/same_as.h>
#include <__config>
#include <__format/format_error.h>
#include <__memory/addressof.h>
#include <__type_traits/is_convertible.h>
#include <__type_traits/is_specialization.h>
#include <cstdint>
#include <ctime>
#include <limits>
@ -77,7 +82,7 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _Date& __date, chrono::weekday _
template <class _Tm, class _Duration>
_LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const chrono::sys_time<_Duration> __tp) {
chrono::sys_days __days = chrono::time_point_cast<chrono::days>(__tp);
chrono::sys_days __days = chrono::floor<chrono::days>(__tp);
chrono::year_month_day __ymd{__days};
_Tm __result = std::__convert_to_tm<_Tm>(chrono::year_month_day{__ymd}, chrono::weekday{__days});
@ -116,12 +121,23 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) {
// ... However, if a flag refers to a "time of day" (e.g. %H, %I, %p,
// etc.), then a specialization of duration is interpreted as the time of
// day elapsed since midnight.
uint64_t __sec = chrono::duration_cast<chrono::seconds>(__value).count();
__sec %= 24 * 3600;
__result.tm_hour = __sec / 3600;
__sec %= 3600;
__result.tm_min = __sec / 60;
__result.tm_sec = __sec % 60;
// Not all values can be converted to hours, it may run into ratio
// conversion errors. In that case the conversion to seconds works.
if constexpr (is_convertible_v<_ChronoT, chrono::hours>) {
auto __hour = chrono::floor<chrono::hours>(__value);
auto __sec = chrono::duration_cast<chrono::seconds>(__value - __hour);
__result.tm_hour = __hour.count() % 24;
__result.tm_min = __sec.count() / 60;
__result.tm_sec = __sec.count() % 60;
} else {
uint64_t __sec = chrono::duration_cast<chrono::seconds>(__value).count();
__sec %= 24 * 3600;
__result.tm_hour = __sec / 3600;
__sec %= 3600;
__result.tm_min = __sec / 60;
__result.tm_sec = __sec % 60;
}
} else if constexpr (same_as<_ChronoT, chrono::day>)
__result.tm_mday = static_cast<unsigned>(__value);
else if constexpr (same_as<_ChronoT, chrono::month>)
@ -159,6 +175,18 @@ _LIBCPP_HIDE_FROM_ABI _Tm __convert_to_tm(const _ChronoT& __value) {
if (__value.hours().count() > std::numeric_limits<decltype(__result.tm_hour)>::max())
std::__throw_format_error("Formatting hh_mm_ss, encountered an hour overflow");
__result.tm_hour = __value.hours().count();
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
} else if constexpr (same_as<_ChronoT, chrono::sys_info>) {
// Has no time information.
} else if constexpr (same_as<_ChronoT, chrono::local_info>) {
// Has no time information.
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
} else if constexpr (__is_specialization_v<_ChronoT, chrono::zoned_time>) {
return std::__convert_to_tm<_Tm>(
chrono::sys_time<typename _ChronoT::duration>{__value.get_local_time().time_since_epoch()});
# endif
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
} else
static_assert(sizeof(_ChronoT) == 0, "Add the missing type specialization");

View file

@ -22,58 +22,73 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class day {
private:
unsigned char __d_;
unsigned char __d_;
public:
day() = default;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept : __d_(static_cast<unsigned char>(__val)) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept { ++__d_; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
_LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept { --__d_; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
_LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d_ >= 1 && __d_ <= 31; }
};
day() = default;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr day(unsigned __val) noexcept
: __d_(static_cast<unsigned char>(__val)) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr day& operator++() noexcept {
++__d_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr day operator++(int) noexcept {
day __tmp = *this;
++(*this);
return __tmp;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr day& operator--() noexcept {
--__d_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr day operator--(int) noexcept {
day __tmp = *this;
--(*this);
return __tmp;
}
_LIBCPP_HIDE_FROM_ABI constexpr day& operator+=(const days& __dd) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr day& operator-=(const days& __dd) noexcept;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __d_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __d_ >= 1 && __d_ <= 31; }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const day& __lhs, const day& __rhs) noexcept {
return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const day& __lhs, const day& __rhs) noexcept
{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept {
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept {
return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
day operator+ (const day& __lhs, const days& __rhs) noexcept
{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
_LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const day& __lhs, const days& __rhs) noexcept {
return day(static_cast<unsigned>(__lhs) + __rhs.count());
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
day operator+ (const days& __lhs, const day& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr day operator+(const days& __lhs, const day& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
day operator- (const day& __lhs, const days& __rhs) noexcept
{ return __lhs + -__rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr day operator-(const day& __lhs, const days& __rhs) noexcept {
return __lhs + -__rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
days operator-(const day& __lhs, const day& __rhs) noexcept
{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
static_cast<int>(static_cast<unsigned>(__rhs))); }
_LIBCPP_HIDE_FROM_ABI inline constexpr days operator-(const day& __lhs, const day& __rhs) noexcept {
return days(static_cast<int>(static_cast<unsigned>(__lhs)) - static_cast<int>(static_cast<unsigned>(__rhs)));
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
day& day::operator+=(const days& __dd) noexcept
{ *this = *this + __dd; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr day& day::operator+=(const days& __dd) noexcept {
*this = *this + __dd;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
day& day::operator-=(const days& __dd) noexcept
{ *this = *this - __dd; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr day& day::operator-=(const days& __dd) noexcept {
*this = *this - __dd;
return *this;
}
} // namespace chrono

View file

@ -29,104 +29,82 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
template <class _Rep, class _Period = ratio<1> >
class _LIBCPP_TEMPLATE_VIS duration;
template <class _Tp>
struct __is_duration : false_type {};
template <class _Rep, class _Period>
struct __is_duration<duration<_Rep, _Period> > : true_type {};
struct __is_duration<duration<_Rep, _Period> > : true_type {};
template <class _Rep, class _Period>
struct __is_duration<const duration<_Rep, _Period> > : true_type {};
struct __is_duration<const duration<_Rep, _Period> > : true_type {};
template <class _Rep, class _Period>
struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
template <class _Rep, class _Period>
struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
} // namespace chrono
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
chrono::duration<_Rep2, _Period2> >
{
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
typename __ratio_gcd<_Period1, _Period2>::type> type;
struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, chrono::duration<_Rep2, _Period2> > {
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, typename __ratio_gcd<_Period1, _Period2>::type>
type;
};
namespace chrono {
// duration_cast
template <class _FromDuration, class _ToDuration,
template <class _FromDuration,
class _ToDuration,
class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
bool = _Period::num == 1,
bool = _Period::den == 1>
bool = _Period::num == 1,
bool = _Period::den == 1>
struct __duration_cast;
template <class _FromDuration, class _ToDuration, class _Period>
struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_ToDuration operator()(const _FromDuration& __fd) const
{
return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
}
struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const {
return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
}
};
template <class _FromDuration, class _ToDuration, class _Period>
struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_ToDuration operator()(const _FromDuration& __fd) const
{
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
return _ToDuration(static_cast<typename _ToDuration::rep>(
static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
}
struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const {
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
return _ToDuration(
static_cast<typename _ToDuration::rep>(static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
}
};
template <class _FromDuration, class _ToDuration, class _Period>
struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_ToDuration operator()(const _FromDuration& __fd) const
{
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
return _ToDuration(static_cast<typename _ToDuration::rep>(
static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
}
struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const {
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
return _ToDuration(
static_cast<typename _ToDuration::rep>(static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
}
};
template <class _FromDuration, class _ToDuration, class _Period>
struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_ToDuration operator()(const _FromDuration& __fd) const
{
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
return _ToDuration(static_cast<typename _ToDuration::rep>(
static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
/ static_cast<_Ct>(_Period::den)));
}
struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration operator()(const _FromDuration& __fd) const {
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
return _ToDuration(static_cast<typename _ToDuration::rep>(
static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) / static_cast<_Ct>(_Period::den)));
}
};
template <class _ToDuration, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
_ToDuration
>::type
duration_cast(const duration<_Rep, _Period>& __fd)
{
return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
template <class _ToDuration, class _Rep, class _Period, __enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration duration_cast(const duration<_Rep, _Period>& __fd) {
return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
}
template <class _Rep>
@ -138,210 +116,204 @@ inline constexpr bool treat_as_floating_point_v = treat_as_floating_point<_Rep>:
#endif
template <class _Rep>
struct _LIBCPP_TEMPLATE_VIS duration_values
{
struct _LIBCPP_TEMPLATE_VIS duration_values {
public:
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT {return numeric_limits<_Rep>::max();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT { return _Rep(0); }
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT { return numeric_limits<_Rep>::max(); }
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT { return numeric_limits<_Rep>::lowest(); }
};
#if _LIBCPP_STD_VER >= 17
template <class _ToDuration, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
_ToDuration
>::type
floor(const duration<_Rep, _Period>& __d)
{
_ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
if (__t > __d)
__t = __t - _ToDuration{1};
return __t;
template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration floor(const duration<_Rep, _Period>& __d) {
_ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
if (__t > __d)
__t = __t - _ToDuration{1};
return __t;
}
template <class _ToDuration, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
_ToDuration
>::type
ceil(const duration<_Rep, _Period>& __d)
{
_ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
if (__t < __d)
__t = __t + _ToDuration{1};
return __t;
template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration ceil(const duration<_Rep, _Period>& __d) {
_ToDuration __t = chrono::duration_cast<_ToDuration>(__d);
if (__t < __d)
__t = __t + _ToDuration{1};
return __t;
}
template <class _ToDuration, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
_ToDuration
>::type
round(const duration<_Rep, _Period>& __d)
{
_ToDuration __lower = chrono::floor<_ToDuration>(__d);
_ToDuration __upper = __lower + _ToDuration{1};
auto __lower_diff = __d - __lower;
auto __upper_diff = __upper - __d;
if (__lower_diff < __upper_diff)
return __lower;
if (__lower_diff > __upper_diff)
return __upper;
return __lower.count() & 1 ? __upper : __lower;
template <class _ToDuration, class _Rep, class _Period, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _ToDuration round(const duration<_Rep, _Period>& __d) {
_ToDuration __lower = chrono::floor<_ToDuration>(__d);
_ToDuration __upper = __lower + _ToDuration{1};
auto __lower_diff = __d - __lower;
auto __upper_diff = __upper - __d;
if (__lower_diff < __upper_diff)
return __lower;
if (__lower_diff > __upper_diff)
return __upper;
return __lower.count() & 1 ? __upper : __lower;
}
#endif
// duration
template <class _Rep, class _Period>
class _LIBCPP_TEMPLATE_VIS duration
{
static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
static_assert(_Period::num > 0, "duration period must be positive");
class _LIBCPP_TEMPLATE_VIS duration {
static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
static_assert(_Period::num > 0, "duration period must be positive");
template <class _R1, class _R2>
struct __no_overflow
template <class _R1, class _R2>
struct __no_overflow {
private:
static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
struct __mul // __overflow == false
{
private:
static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
struct __mul // __overflow == false
{
static const intmax_t value = _Xp * _Yp;
};
template <intmax_t _Xp, intmax_t _Yp>
struct __mul<_Xp, _Yp, true>
{
static const intmax_t value = 1;
};
public:
static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
typedef ratio<__mul<__n1, __d2, !value>::value,
__mul<__n2, __d1, !value>::value> type;
static const intmax_t value = _Xp * _Yp;
};
public:
typedef _Rep rep;
typedef typename _Period::type period;
private:
rep __rep_;
public:
template <intmax_t _Xp, intmax_t _Yp>
struct __mul<_Xp, _Yp, true> {
static const intmax_t value = 1;
};
public:
static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
typedef ratio<__mul<__n1, __d2, !value>::value, __mul<__n2, __d1, !value>::value> type;
};
public:
typedef _Rep rep;
typedef typename _Period::type period;
private:
rep __rep_;
public:
#ifndef _LIBCPP_CXX03_LANG
constexpr duration() = default;
constexpr duration() = default;
#else
_LIBCPP_HIDE_FROM_ABI duration() {}
_LIBCPP_HIDE_FROM_ABI duration() {}
#endif
template <class _Rep2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
explicit duration(const _Rep2& __r,
typename enable_if
<
is_convertible<const _Rep2&, rep>::value &&
(treat_as_floating_point<rep>::value ||
!treat_as_floating_point<_Rep2>::value)
>::type* = nullptr)
: __rep_(__r) {}
template <class _Rep2,
__enable_if_t<is_convertible<const _Rep2&, rep>::value &&
(treat_as_floating_point<rep>::value || !treat_as_floating_point<_Rep2>::value),
int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit duration(const _Rep2& __r) : __rep_(__r) {}
// conversions
template <class _Rep2, class _Period2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
duration(const duration<_Rep2, _Period2>& __d,
typename enable_if
<
__no_overflow<_Period2, period>::value && (
treat_as_floating_point<rep>::value ||
(__no_overflow<_Period2, period>::type::den == 1 &&
!treat_as_floating_point<_Rep2>::value))
>::type* = nullptr)
: __rep_(chrono::duration_cast<duration>(__d).count()) {}
// conversions
template <class _Rep2,
class _Period2,
__enable_if_t<__no_overflow<_Period2, period>::value && (treat_as_floating_point<rep>::value ||
(__no_overflow<_Period2, period>::type::den == 1 &&
!treat_as_floating_point<_Rep2>::value)),
int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration(const duration<_Rep2, _Period2>& __d)
: __rep_(chrono::duration_cast<duration>(__d).count()) {}
// observer
// observer
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR rep count() const { return __rep_; }
// arithmetic
// arithmetic
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator++() {++__rep_; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator++(int) {return duration(__rep_++);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator--() {--__rep_; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator--(int) {return duration(__rep_--);}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {
return typename common_type<duration>::type(*this);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {
return typename common_type<duration>::type(-__rep_);
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator++() {
++__rep_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator++(int) { return duration(__rep_++); }
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator--() {
--__rep_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration operator--(int) { return duration(__rep_--); }
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator+=(const duration& __d) {
__rep_ += __d.count();
return *this;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator-=(const duration& __d) {
__rep_ -= __d.count();
return *this;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator*=(const rep& __rhs) {__rep_ *= __rhs; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator/=(const rep& __rhs) {__rep_ /= __rhs; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const rep& __rhs) {__rep_ %= __rhs; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const duration& __rhs) {__rep_ %= __rhs.count(); return *this;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator*=(const rep& __rhs) {
__rep_ *= __rhs;
return *this;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator/=(const rep& __rhs) {
__rep_ /= __rhs;
return *this;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const rep& __rhs) {
__rep_ %= __rhs;
return *this;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 duration& operator%=(const duration& __rhs) {
__rep_ %= __rhs.count();
return *this;
}
// special values
// special values
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {return duration(duration_values<rep>::min());}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {return duration(duration_values<rep>::max());}
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {
return duration(duration_values<rep>::zero());
}
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {
return duration(duration_values<rep>::min());
}
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {
return duration(duration_values<rep>::max());
}
};
typedef duration<long long, nano> nanoseconds;
typedef duration<long long, micro> microseconds;
typedef duration<long long, milli> milliseconds;
typedef duration<long long > seconds;
typedef duration< long, ratio< 60> > minutes;
typedef duration< long, ratio<3600> > hours;
typedef duration<long long, nano> nanoseconds;
typedef duration<long long, micro> microseconds;
typedef duration<long long, milli> milliseconds;
typedef duration<long long > seconds;
typedef duration< long, ratio< 60> > minutes;
typedef duration< long, ratio<3600> > hours;
#if _LIBCPP_STD_VER >= 20
typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years;
typedef duration< int, ratio_divide<years::period, ratio<12>>> months;
typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years;
typedef duration< int, ratio_divide<years::period, ratio<12>>> months;
#endif
// Duration ==
template <class _LhsDuration, class _RhsDuration>
struct __duration_eq
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
{
typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
return _Ct(__lhs).count() == _Ct(__rhs).count();
}
struct __duration_eq {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const {
typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
return _Ct(__lhs).count() == _Ct(__rhs).count();
}
};
template <class _LhsDuration>
struct __duration_eq<_LhsDuration, _LhsDuration>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
{return __lhs.count() == __rhs.count();}
struct __duration_eq<_LhsDuration, _LhsDuration> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const {
return __lhs.count() == __rhs.count();
}
};
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
}
#if _LIBCPP_STD_VER <= 17
@ -349,12 +321,9 @@ operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period
// Duration !=
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return !(__lhs == __rhs);
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
return !(__lhs == __rhs);
}
#endif // _LIBCPP_STD_VER <= 17
@ -362,76 +331,58 @@ operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period
// Duration <
template <class _LhsDuration, class _RhsDuration>
struct __duration_lt
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
{
typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
return _Ct(__lhs).count() < _Ct(__rhs).count();
}
struct __duration_lt {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const {
typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
return _Ct(__lhs).count() < _Ct(__rhs).count();
}
};
template <class _LhsDuration>
struct __duration_lt<_LhsDuration, _LhsDuration>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
{return __lhs.count() < __rhs.count();}
struct __duration_lt<_LhsDuration, _LhsDuration> {
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const {
return __lhs.count() < __rhs.count();
}
};
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
operator<(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
}
// Duration >
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return __rhs < __lhs;
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
operator>(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
return __rhs < __lhs;
}
// Duration <=
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return !(__rhs < __lhs);
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
return !(__rhs < __lhs);
}
// Duration >=
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return !(__lhs < __rhs);
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool
operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
return !(__lhs < __rhs);
}
#if _LIBCPP_STD_VER >= 20
template<class _Rep1, class _Period1, class _Rep2, class _Period2>
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
requires three_way_comparable<common_type_t<_Rep1, _Rep2>>
_LIBCPP_HIDE_FROM_ABI
constexpr auto operator<=>(const duration<_Rep1, _Period1>& __lhs,
const duration<_Rep2, _Period2>& __rhs)
{
using _Ct = common_type_t<duration<_Rep1, _Period1>, duration<_Rep2, _Period2>>;
return _Ct(__lhs).count() <=> _Ct(__rhs).count();
_LIBCPP_HIDE_FROM_ABI constexpr auto
operator<=>(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
using _Ct = common_type_t<duration<_Rep1, _Period1>, duration<_Rep2, _Period2>>;
return _Ct(__lhs).count() <=> _Ct(__rhs).count();
}
#endif // _LIBCPP_STD_VER >= 20
@ -439,193 +390,151 @@ constexpr auto operator<=>(const duration<_Rep1, _Period1>& __lhs,
// Duration +
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
}
// Duration -
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
}
// Duration *
template <class _Rep1, class _Period, class _Rep2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
>::type
operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
{
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef duration<_Cr, _Period> _Cd;
return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
template <class _Rep1,
class _Period,
class _Rep2,
__enable_if_t<is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) {
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef duration<_Cr, _Period> _Cd;
return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
}
template <class _Rep1, class _Period, class _Rep2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
>::type
operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
{
return __d * __s;
template <class _Rep1,
class _Period,
class _Rep2,
__enable_if_t<is_convertible<const _Rep1&, typename common_type<_Rep1, _Rep2>::type>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) {
return __d * __s;
}
// Duration /
template <class _Rep1, class _Period, class _Rep2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
!__is_duration<_Rep2>::value &&
is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
>::type
operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
{
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef duration<_Cr, _Period> _Cd;
return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
template <class _Rep1,
class _Period,
class _Rep2,
__enable_if_t<!__is_duration<_Rep2>::value &&
is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value,
int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) {
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef duration<_Cr, _Period> _Cd;
return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
}
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename common_type<_Rep1, _Rep2>::type
operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
return _Ct(__lhs).count() / _Ct(__rhs).count();
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR typename common_type<_Rep1, _Rep2>::type
operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
return _Ct(__lhs).count() / _Ct(__rhs).count();
}
// Duration %
template <class _Rep1, class _Period, class _Rep2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
!__is_duration<_Rep2>::value &&
is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
>::type
operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
{
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef duration<_Cr, _Period> _Cd;
return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
template <class _Rep1,
class _Period,
class _Rep2,
__enable_if_t<!__is_duration<_Rep2>::value &&
is_convertible<const _Rep2&, typename common_type<_Rep1, _Rep2>::type>::value,
int> = 0>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR duration<typename common_type<_Rep1, _Rep2>::type, _Period>
operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) {
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef duration<_Cr, _Period> _Cd;
return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
}
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
}
} // namespace chrono
#if _LIBCPP_STD_VER >= 14
// Suffixes for duration literals [time.duration.literals]
inline namespace literals
{
inline namespace chrono_literals
{
inline namespace literals {
inline namespace chrono_literals {
_LIBCPP_HIDE_FROM_ABI constexpr chrono::hours operator""h(unsigned long long __h)
{
return chrono::hours(static_cast<chrono::hours::rep>(__h));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::hours operator""h(unsigned long long __h) {
return chrono::hours(static_cast<chrono::hours::rep>(__h));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
{
return chrono::duration<long double, ratio<3600,1>>(__h);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, ratio<3600, 1>> operator""h(long double __h) {
return chrono::duration<long double, ratio<3600, 1>>(__h);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes operator""min(unsigned long long __m) {
return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes operator""min(unsigned long long __m)
{
return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, ratio<60, 1>> operator""min(long double __m) {
return chrono::duration<long double, ratio<60, 1>>(__m);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
{
return chrono::duration<long double, ratio<60,1>> (__m);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds operator""s(unsigned long long __s) {
return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double> operator""s(long double __s) {
return chrono::duration<long double>(__s);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds operator""s(unsigned long long __s)
{
return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::milliseconds operator""ms(unsigned long long __ms) {
return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double> operator""s(long double __s)
{
return chrono::duration<long double> (__s);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, milli> operator""ms(long double __ms) {
return chrono::duration<long double, milli>(__ms);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::microseconds operator""us(unsigned long long __us) {
return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
{
return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, micro> operator""us(long double __us) {
return chrono::duration<long double, micro>(__us);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
{
return chrono::duration<long double, milli>(__ms);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) {
return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::microseconds operator""us(unsigned long long __us)
{
return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, micro> operator""us(long double __us)
{
return chrono::duration<long double, micro> (__us);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
{
return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
{
return chrono::duration<long double, nano> (__ns);
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::duration<long double, nano> operator""ns(long double __ns) {
return chrono::duration<long double, nano>(__ns);
}
} // namespace chrono_literals
} // namespace literals
namespace chrono { // hoist the literals into namespace std::chrono
using namespace literals::chrono_literals;
using namespace literals::chrono_literals;
} // namespace chrono
#endif // _LIBCPP_STD_VER >= 14

135
third_party/libcxx/__chrono/exception.h vendored Normal file
View file

@ -0,0 +1,135 @@
// -*- 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_EXCEPTION_H
#define _LIBCPP___CHRONO_EXCEPTION_H
#include <version>
// Enable the contents of the header only when libc++ was built with experimental features enabled.
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
# include <__chrono/calendar.h>
# include <__chrono/local_info.h>
# include <__chrono/time_point.h>
# include <__config>
# include <__configuration/availability.h>
# include <__verbose_abort>
# include <format>
# include <stdexcept>
# include <string>
# 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 nonexistent_local_time : public runtime_error {
public:
template <class _Duration>
_LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const local_time<_Duration>& __time, const local_info& __info)
: runtime_error{__create_message(__time, __info)} {
// [time.zone.exception.nonexist]/2
// Preconditions: i.result == local_info::nonexistent is true.
// The value of __info.result is not used.
_LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::nonexistent,
"creating an nonexistent_local_time from a local_info that is not non-existent");
}
_LIBCPP_HIDE_FROM_ABI nonexistent_local_time(const nonexistent_local_time&) = default;
_LIBCPP_HIDE_FROM_ABI nonexistent_local_time& operator=(const nonexistent_local_time&) = default;
_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~nonexistent_local_time() override; // exported as key function
private:
template <class _Duration>
_LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) {
return std::format(
R"({} is in a gap between
{} {} and
{} {} which are both equivalent to
{} UTC)",
__time,
local_seconds{__info.first.end.time_since_epoch()} + __info.first.offset,
__info.first.abbrev,
local_seconds{__info.second.begin.time_since_epoch()} + __info.second.offset,
__info.second.abbrev,
__info.first.end);
}
};
template <class _Duration>
_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_nonexistent_local_time(
[[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) {
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
throw nonexistent_local_time(__time, __info);
# else
_LIBCPP_VERBOSE_ABORT("nonexistent_local_time was thrown in -fno-exceptions mode");
# endif
}
class ambiguous_local_time : public runtime_error {
public:
template <class _Duration>
_LIBCPP_HIDE_FROM_ABI ambiguous_local_time(const local_time<_Duration>& __time, const local_info& __info)
: runtime_error{__create_message(__time, __info)} {
// [time.zone.exception.ambig]/2
// Preconditions: i.result == local_info::ambiguous is true.
// The value of __info.result is not used.
_LIBCPP_ASSERT_PEDANTIC(__info.result == local_info::ambiguous,
"creating an ambiguous_local_time from a local_info that is not ambiguous");
}
_LIBCPP_HIDE_FROM_ABI ambiguous_local_time(const ambiguous_local_time&) = default;
_LIBCPP_HIDE_FROM_ABI ambiguous_local_time& operator=(const ambiguous_local_time&) = default;
_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI ~ambiguous_local_time() override; // exported as key function
private:
template <class _Duration>
_LIBCPP_HIDE_FROM_ABI string __create_message(const local_time<_Duration>& __time, const local_info& __info) {
return std::format(
// There are two spaces after the full-stop; this has been verified
// in the sources of the Standard.
R"({0} is ambiguous. It could be
{0} {1} == {2} UTC or
{0} {3} == {4} UTC)",
__time,
__info.first.abbrev,
__time - __info.first.offset,
__info.second.abbrev,
__time - __info.second.offset);
}
};
template <class _Duration>
_LIBCPP_NORETURN _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI void __throw_ambiguous_local_time(
[[maybe_unused]] const local_time<_Duration>& __time, [[maybe_unused]] const local_info& __info) {
# ifndef _LIBCPP_HAS_NO_EXCEPTIONS
throw ambiguous_local_time(__time, __info);
# else
_LIBCPP_VERBOSE_ABORT("ambiguous_local_time was thrown in -fno-exceptions mode");
# endif
}
} // namespace chrono
# endif // _LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // _LIBCPP___CHRONO_EXCEPTION_H

View file

@ -10,7 +10,6 @@
#ifndef _LIBCPP___CHRONO_FILE_CLOCK_H
#define _LIBCPP___CHRONO_FILE_CLOCK_H
#include <__availability>
#include <__chrono/duration.h>
#include <__chrono/system_clock.h>
#include <__chrono/time_point.h>
@ -31,13 +30,12 @@ _LIBCPP_END_NAMESPACE_FILESYSTEM
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
// [time.clock.file], type file_clock
using file_clock = _VSTD_FS::_FilesystemClock;
using file_clock = filesystem::_FilesystemClock;
template<class _Duration>
template <class _Duration>
using file_time = time_point<file_clock, _Duration>;
} // namespace chrono
@ -49,35 +47,32 @@ _LIBCPP_END_NAMESPACE_STD
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
struct _FilesystemClock {
#if !defined(_LIBCPP_HAS_NO_INT128)
# if !defined(_LIBCPP_HAS_NO_INT128)
typedef __int128_t rep;
typedef nano period;
#else
# else
typedef long long rep;
typedef nano period;
#endif
# endif
typedef chrono::duration<rep, period> duration;
typedef chrono::time_point<_FilesystemClock> time_point;
_LIBCPP_EXPORTED_FROM_ABI
static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false;
_LIBCPP_EXPORTED_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false;
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept;
_LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_EXPORTED_FROM_ABI static time_point now() noexcept;
#if _LIBCPP_STD_VER >= 20
# if _LIBCPP_STD_VER >= 20
template <class _Duration>
_LIBCPP_HIDE_FROM_ABI
static chrono::sys_time<_Duration> to_sys(const chrono::file_time<_Duration>& __t) {
_LIBCPP_HIDE_FROM_ABI static chrono::sys_time<_Duration> to_sys(const chrono::file_time<_Duration>& __t) {
return chrono::sys_time<_Duration>(__t.time_since_epoch());
}
template <class _Duration>
_LIBCPP_HIDE_FROM_ABI
static chrono::file_time<_Duration> from_sys(const chrono::sys_time<_Duration>& __t) {
_LIBCPP_HIDE_FROM_ABI static chrono::file_time<_Duration> from_sys(const chrono::sys_time<_Duration>& __t) {
return chrono::file_time<_Duration>(__t.time_since_epoch());
}
#endif // _LIBCPP_STD_VER >= 20
# endif // _LIBCPP_STD_VER >= 20
};
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // !_LIBCPP_CXX03_LANG

View file

@ -10,6 +10,7 @@
#ifndef _LIBCPP___CHRONO_FORMATTER_H
#define _LIBCPP___CHRONO_FORMATTER_H
#include <__algorithm/ranges_copy.h>
#include <__chrono/calendar.h>
#include <__chrono/concepts.h>
#include <__chrono/convert_to_tm.h>
@ -17,12 +18,14 @@
#include <__chrono/duration.h>
#include <__chrono/file_clock.h>
#include <__chrono/hh_mm_ss.h>
#include <__chrono/local_info.h>
#include <__chrono/month.h>
#include <__chrono/month_weekday.h>
#include <__chrono/monthday.h>
#include <__chrono/ostream.h>
#include <__chrono/parser_std_format_spec.h>
#include <__chrono/statically_widen.h>
#include <__chrono/sys_info.h>
#include <__chrono/system_clock.h>
#include <__chrono/time_point.h>
#include <__chrono/weekday.h>
@ -30,6 +33,7 @@
#include <__chrono/year_month.h>
#include <__chrono/year_month_day.h>
#include <__chrono/year_month_weekday.h>
#include <__chrono/zoned_time.h>
#include <__concepts/arithmetic.h>
#include <__concepts/same_as.h>
#include <__config>
@ -38,13 +42,14 @@
#include <__format/format_functions.h>
#include <__format/format_parse_context.h>
#include <__format/formatter.h>
#include <__format/formatter_output.h>
#include <__format/parser_std_format_spec.h>
#include <__format/write_escaped.h>
#include <__memory/addressof.h>
#include <__type_traits/is_specialization.h>
#include <cmath>
#include <ctime>
#include <limits>
#include <sstream>
#include <string>
#include <string_view>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@ -80,12 +85,15 @@ namespace __formatter {
// small). Therefore a duration uses its own conversion.
template <class _CharT, class _Rep, class _Period>
_LIBCPP_HIDE_FROM_ABI void
__format_sub_seconds(const chrono::duration<_Rep, _Period>& __value, basic_stringstream<_CharT>& __sstr) {
__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::duration<_Rep, _Period>& __value) {
__sstr << std::use_facet<numpunct<_CharT>>(__sstr.getloc()).decimal_point();
using __duration = chrono::duration<_Rep, _Period>;
auto __fraction = __value - chrono::duration_cast<chrono::seconds>(__value);
// Converts a negative fraction to its positive value.
if (__value < chrono::seconds{0} && __fraction != __duration{0})
__fraction += chrono::seconds{1};
if constexpr (chrono::treat_as_floating_point_v<_Rep>)
// When the floating-point value has digits itself they are ignored based
// on the wording in [tab:time.format.spec]
@ -101,23 +109,23 @@ __format_sub_seconds(const chrono::duration<_Rep, _Period>& __value, basic_strin
// https://godbolt.org/z/6dsbnW8ba
std::format_to(std::ostreambuf_iterator<_CharT>{__sstr},
_LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}.0f}"),
__fraction.count(),
chrono::duration_cast<typename chrono::hh_mm_ss<__duration>::precision>(__fraction).count(),
chrono::hh_mm_ss<__duration>::fractional_width);
else
std::format_to(std::ostreambuf_iterator<_CharT>{__sstr},
_LIBCPP_STATICALLY_WIDEN(_CharT, "{:0{}}"),
__fraction.count(),
chrono::duration_cast<typename chrono::hh_mm_ss<__duration>::precision>(__fraction).count(),
chrono::hh_mm_ss<__duration>::fractional_width);
}
template <class _CharT, __is_time_point _Tp>
_LIBCPP_HIDE_FROM_ABI void __format_sub_seconds(const _Tp& __value, basic_stringstream<_CharT>& __sstr) {
__formatter::__format_sub_seconds(__value.time_since_epoch(), __sstr);
_LIBCPP_HIDE_FROM_ABI void __format_sub_seconds(basic_stringstream<_CharT>& __sstr, const _Tp& __value) {
__formatter::__format_sub_seconds(__sstr, __value.time_since_epoch());
}
template <class _CharT, class _Duration>
_LIBCPP_HIDE_FROM_ABI void
__format_sub_seconds(const chrono::hh_mm_ss<_Duration>& __value, basic_stringstream<_CharT>& __sstr) {
__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::hh_mm_ss<_Duration>& __value) {
__sstr << std::use_facet<numpunct<_CharT>>(__sstr.getloc()).decimal_point();
if constexpr (chrono::treat_as_floating_point_v<typename _Duration::rep>)
std::format_to(std::ostreambuf_iterator<_CharT>{__sstr},
@ -131,10 +139,24 @@ __format_sub_seconds(const chrono::hh_mm_ss<_Duration>& __value, basic_stringstr
__value.fractional_width);
}
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
!defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
template <class _CharT, class _Duration, class _TimeZonePtr>
_LIBCPP_HIDE_FROM_ABI void
__format_sub_seconds(basic_stringstream<_CharT>& __sstr, const chrono::zoned_time<_Duration, _TimeZonePtr>& __value) {
__formatter::__format_sub_seconds(__sstr, __value.get_local_time().time_since_epoch());
}
# endif
template <class _Tp>
consteval bool __use_fraction() {
if constexpr (__is_time_point<_Tp>)
return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB) && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && \
!defined(_LIBCPP_HAS_NO_FILESYSTEM) && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
return chrono::hh_mm_ss<typename _Tp::duration>::fractional_width;
# endif
else if constexpr (chrono::__is_duration<_Tp>::value)
return chrono::hh_mm_ss<_Tp>::fractional_width;
else if constexpr (__is_hh_mm_ss<_Tp>)
@ -144,7 +166,7 @@ consteval bool __use_fraction() {
}
template <class _CharT>
_LIBCPP_HIDE_FROM_ABI void __format_year(int __year, basic_stringstream<_CharT>& __sstr) {
_LIBCPP_HIDE_FROM_ABI void __format_year(basic_stringstream<_CharT>& __sstr, int __year) {
if (__year < 0) {
__sstr << _CharT('-');
__year = -__year;
@ -160,7 +182,7 @@ _LIBCPP_HIDE_FROM_ABI void __format_year(int __year, basic_stringstream<_CharT>&
}
template <class _CharT>
_LIBCPP_HIDE_FROM_ABI void __format_century(int __year, basic_stringstream<_CharT>& __sstr) {
_LIBCPP_HIDE_FROM_ABI void __format_century(basic_stringstream<_CharT>& __sstr, int __year) {
// TODO FMT Write an issue
// [tab:time.format.spec]
// %C The year divided by 100 using floored division. If the result is a
@ -171,10 +193,56 @@ _LIBCPP_HIDE_FROM_ABI void __format_century(int __year, basic_stringstream<_Char
__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __century);
}
// Implements the %z format specifier according to [tab:time.format.spec], where
// '__modifier' signals %Oz or %Ez were used. (Both modifiers behave the same,
// so there is no need to distinguish between them.)
template <class _CharT>
_LIBCPP_HIDE_FROM_ABI void
__format_zone_offset(basic_stringstream<_CharT>& __sstr, chrono::seconds __offset, bool __modifier) {
if (__offset < 0s) {
__sstr << _CharT('-');
__offset = -__offset;
} else {
__sstr << _CharT('+');
}
chrono::hh_mm_ss __hms{__offset};
std::ostreambuf_iterator<_CharT> __out_it{__sstr};
// Note HMS does not allow formatting hours > 23, but the offset is not limited to 24H.
std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __hms.hours().count());
if (__modifier)
__sstr << _CharT(':');
std::format_to(__out_it, _LIBCPP_STATICALLY_WIDEN(_CharT, "{:02}"), __hms.minutes().count());
}
// Helper to store the time zone information needed for formatting.
struct _LIBCPP_HIDE_FROM_ABI __time_zone {
// Typically these abbreviations are short and fit in the string's internal
// buffer.
string __abbrev;
chrono::seconds __offset;
};
template <class _Tp>
_LIBCPP_HIDE_FROM_ABI __time_zone __convert_to_time_zone([[maybe_unused]] const _Tp& __value) {
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
if constexpr (same_as<_Tp, chrono::sys_info>)
return {__value.abbrev, __value.offset};
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
return __formatter::__convert_to_time_zone(__value.get_info());
# endif
else
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
return {"UTC", chrono::seconds{0}};
}
template <class _CharT, class _Tp>
_LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
const _Tp& __value, basic_stringstream<_CharT>& __sstr, basic_string_view<_CharT> __chrono_specs) {
basic_stringstream<_CharT>& __sstr, const _Tp& __value, basic_string_view<_CharT> __chrono_specs) {
tm __t = std::__convert_to_tm<tm>(__value);
__time_zone __z = __formatter::__convert_to_time_zone(__value);
const auto& __facet = std::use_facet<time_put<_CharT>>(__sstr.getloc());
for (auto __it = __chrono_specs.begin(); __it != __chrono_specs.end(); ++__it) {
if (*__it == _CharT('%')) {
@ -197,9 +265,10 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
// strftime's output is only defined in the range [00, 99].
int __year = __t.tm_year + 1900;
if (__year < 1000 || __year > 9999)
__formatter::__format_century(__year, __sstr);
__formatter::__format_century(__sstr, __year);
else
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
__facet.put(
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
} break;
case _CharT('j'):
@ -210,7 +279,8 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
// an intemediate step.
__sstr << chrono::duration_cast<chrono::days>(chrono::duration_cast<chrono::seconds>(__value)).count();
else
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
__facet.put(
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
break;
case _CharT('q'):
@ -238,9 +308,10 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
case _CharT('S'):
case _CharT('T'):
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
__facet.put(
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
if constexpr (__use_fraction<_Tp>())
__formatter::__format_sub_seconds(__value, __sstr);
__formatter::__format_sub_seconds(__sstr, __value);
break;
// Unlike time_put and strftime the formatting library requires %Y
@ -281,21 +352,24 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
// Depending on the platform's libc the range of supported years is
// limited. Intead of of testing all conditions use the internal
// implementation unconditionally.
__formatter::__format_year(__t.tm_year + 1900, __sstr);
__formatter::__format_year(__sstr, __t.tm_year + 1900);
break;
case _CharT('F'): {
int __year = __t.tm_year + 1900;
if (__year < 1000) {
__formatter::__format_year(__year, __sstr);
__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
} else
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
} break;
case _CharT('F'):
// Depending on the platform's libc the range of supported years is
// limited. Instead of testing all conditions use the internal
// implementation unconditionally.
__formatter::__format_year(__sstr, __t.tm_year + 1900);
__sstr << std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "-{:02}-{:02}"), __t.tm_mon + 1, __t.tm_mday);
break;
case _CharT('z'):
__formatter::__format_zone_offset(__sstr, __z.__offset, false);
break;
case _CharT('Z'):
// TODO FMT Add proper timezone support.
__sstr << _LIBCPP_STATICALLY_WIDEN(_CharT, "UTC");
// __abbrev is always a char so the copy may convert.
ranges::copy(__z.__abbrev, std::ostreambuf_iterator<_CharT>{__sstr});
break;
case _CharT('O'):
@ -305,17 +379,25 @@ _LIBCPP_HIDE_FROM_ABI void __format_chrono_using_chrono_specs(
// fractional part should be formatted.
if (*(__it + 1) == 'S') {
++__it;
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
__formatter::__format_sub_seconds(__value, __sstr);
__facet.put(
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
__formatter::__format_sub_seconds(__sstr, __value);
break;
}
}
// Oz produces the same output as Ez below.
[[fallthrough]];
case _CharT('E'):
++__it;
if (*__it == 'z') {
__formatter::__format_zone_offset(__sstr, __z.__offset, true);
break;
}
[[fallthrough]];
default:
__facet.put({__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
__facet.put(
{__sstr}, __sstr, _CharT(' '), std::addressof(__t), std::to_address(__s), std::to_address(__it + 1));
break;
}
} else {
@ -360,6 +442,17 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_ok(const _Tp& __value) {
return __value.weekday().ok();
else if constexpr (__is_hh_mm_ss<_Tp>)
return true;
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
else if constexpr (same_as<_Tp, chrono::sys_info>)
return true;
else if constexpr (same_as<_Tp, chrono::local_info>)
return true;
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
return true;
# endif
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
else
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
}
@ -400,6 +493,17 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __weekday_name_ok(const _Tp& __value) {
return __value.weekday().ok();
else if constexpr (__is_hh_mm_ss<_Tp>)
return true;
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
else if constexpr (same_as<_Tp, chrono::sys_info>)
return true;
else if constexpr (same_as<_Tp, chrono::local_info>)
return true;
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
return true;
# endif
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
else
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
}
@ -440,6 +544,17 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __date_ok(const _Tp& __value) {
return __value.ok();
else if constexpr (__is_hh_mm_ss<_Tp>)
return true;
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
else if constexpr (same_as<_Tp, chrono::sys_info>)
return true;
else if constexpr (same_as<_Tp, chrono::local_info>)
return true;
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
return true;
# endif
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
else
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
}
@ -480,6 +595,17 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool __month_name_ok(const _Tp& __value) {
return __value.month().ok();
else if constexpr (__is_hh_mm_ss<_Tp>)
return true;
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
else if constexpr (same_as<_Tp, chrono::sys_info>)
return true;
else if constexpr (same_as<_Tp, chrono::local_info>)
return true;
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
else if constexpr (__is_specialization_v<_Tp, chrono::zoned_time>)
return true;
# endif
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
else
static_assert(sizeof(_Tp) == 0, "Add the missing type specialization");
}
@ -505,28 +631,35 @@ __format_chrono(const _Tp& __value,
__sstr << __value;
else {
if constexpr (chrono::__is_duration<_Tp>::value) {
if (__value < __value.zero())
__sstr << _CharT('-');
__formatter::__format_chrono_using_chrono_specs(chrono::abs(__value), __sstr, __chrono_specs);
// A duration can be a user defined arithmetic type. Users may specialize
// numeric_limits, but they may not specialize is_signed.
if constexpr (numeric_limits<typename _Tp::rep>::is_signed) {
if (__value < __value.zero()) {
__sstr << _CharT('-');
__formatter::__format_chrono_using_chrono_specs(__sstr, -__value, __chrono_specs);
} else
__formatter::__format_chrono_using_chrono_specs(__sstr, __value, __chrono_specs);
} else
__formatter::__format_chrono_using_chrono_specs(__sstr, __value, __chrono_specs);
// TODO FMT When keeping the precision it will truncate the string.
// Note that the behaviour what the precision does isn't specified.
__specs.__precision_ = -1;
} else {
// Test __weekday_name_ before __weekday_ to give a better error.
if (__specs.__chrono_.__weekday_name_ && !__formatter::__weekday_name_ok(__value))
std::__throw_format_error("formatting a weekday name needs a valid weekday");
std::__throw_format_error("Formatting a weekday name needs a valid weekday");
if (__specs.__chrono_.__weekday_ && !__formatter::__weekday_ok(__value))
std::__throw_format_error("formatting a weekday needs a valid weekday");
std::__throw_format_error("Formatting a weekday needs a valid weekday");
if (__specs.__chrono_.__day_of_year_ && !__formatter::__date_ok(__value))
std::__throw_format_error("formatting a day of year needs a valid date");
std::__throw_format_error("Formatting a day of year needs a valid date");
if (__specs.__chrono_.__week_of_year_ && !__formatter::__date_ok(__value))
std::__throw_format_error("formatting a week of year needs a valid date");
std::__throw_format_error("Formatting a week of year needs a valid date");
if (__specs.__chrono_.__month_name_ && !__formatter::__month_name_ok(__value))
std::__throw_format_error("formatting a month name from an invalid month number");
std::__throw_format_error("Formatting a month name from an invalid month number");
if constexpr (__is_hh_mm_ss<_Tp>) {
// Note this is a pedantic intepretation of the Standard. A hh_mm_ss
@ -545,13 +678,13 @@ __format_chrono(const _Tp& __value,
// - Write it as not valid,
// - or write the number of days.
if (__specs.__chrono_.__hour_ && __value.hours().count() > 23)
std::__throw_format_error("formatting a hour needs a valid value");
std::__throw_format_error("Formatting a hour needs a valid value");
if (__value.is_negative())
__sstr << _CharT('-');
}
__formatter::__format_chrono_using_chrono_specs(__value, __sstr, __chrono_specs);
__formatter::__format_chrono_using_chrono_specs(__sstr, __value, __chrono_specs);
}
}
@ -635,8 +768,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::day, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::day, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -647,8 +779,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -659,8 +790,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -671,8 +801,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -683,8 +812,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_indexed, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_indexed, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -695,8 +823,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_last, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::weekday_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -707,8 +834,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -719,8 +845,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day_last, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_day_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -731,8 +856,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -743,8 +867,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday_last, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -755,8 +878,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -767,8 +889,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -779,8 +900,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day_last, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_day_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -791,8 +911,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -803,8 +922,7 @@ public:
};
template <__fmt_char_type _CharT>
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday_last, _CharT>
: public __formatter_chrono<_CharT> {
struct _LIBCPP_TEMPLATE_VIS formatter<chrono::year_month_weekday_last, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
@ -824,6 +942,47 @@ public:
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__time);
}
};
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
template <__fmt_char_type _CharT>
struct formatter<chrono::sys_info, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
template <class _ParseContext>
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__time_zone);
}
};
template <__fmt_char_type _CharT>
struct formatter<chrono::local_info, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
template <class _ParseContext>
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags{});
}
};
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
// Note due to how libc++'s formatters are implemented there is no need to add
// the exposition only local-time-format-t abstraction.
template <class _Duration, class _TimeZonePtr, __fmt_char_type _CharT>
struct formatter<chrono::zoned_time<_Duration, _TimeZonePtr>, _CharT> : public __formatter_chrono<_CharT> {
public:
using _Base = __formatter_chrono<_CharT>;
template <class _ParseContext>
_LIBCPP_HIDE_FROM_ABI constexpr typename _ParseContext::iterator parse(_ParseContext& __ctx) {
return _Base::__parse(__ctx, __format_spec::__fields_chrono, __format_spec::__flags::__clock);
}
};
# endif // !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) &&
// !defined(_LIBCPP_HAS_NO_LOCALIZATION)
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // if _LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD

View file

@ -24,85 +24,84 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
template <class _Duration>
class hh_mm_ss
{
class hh_mm_ss {
private:
static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
using __CommonType = common_type_t<_Duration, chrono::seconds>;
static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
using __CommonType = common_type_t<_Duration, chrono::seconds>;
_LIBCPP_HIDE_FROM_ABI static constexpr uint64_t __pow10(unsigned __exp)
{
uint64_t __ret = 1;
for (unsigned __i = 0; __i < __exp; ++__i)
__ret *= 10U;
return __ret;
}
_LIBCPP_HIDE_FROM_ABI static constexpr uint64_t __pow10(unsigned __exp) {
uint64_t __ret = 1;
for (unsigned __i = 0; __i < __exp; ++__i)
__ret *= 10U;
return __ret;
}
_LIBCPP_HIDE_FROM_ABI static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0)
{
if (__n >= 2 && __d != 0 && __w < 19)
return 1 + __width(__n, __d % __n * 10, __w+1);
return 0;
}
_LIBCPP_HIDE_FROM_ABI static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0) {
if (__n >= 2 && __d != 0 && __w < 19)
return 1 + __width(__n, __d % __n * 10, __w + 1);
return 0;
}
public:
_LIBCPP_HIDE_FROM_ABI static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ?
__width(__CommonType::period::den) : 6u;
using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>;
_LIBCPP_HIDE_FROM_ABI static unsigned constexpr fractional_width =
__width(__CommonType::period::den) < 19 ? __width(__CommonType::period::den) : 6u;
using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>;
_LIBCPP_HIDE_FROM_ABI constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {}
_LIBCPP_HIDE_FROM_ABI constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {}
_LIBCPP_HIDE_FROM_ABI constexpr explicit hh_mm_ss(_Duration __d) noexcept :
__is_neg_(__d < _Duration(0)),
__h_(chrono::duration_cast<chrono::hours> (chrono::abs(__d))),
_LIBCPP_HIDE_FROM_ABI constexpr explicit hh_mm_ss(_Duration __d) noexcept
: __is_neg_(__d < _Duration(0)),
__h_(chrono::duration_cast<chrono::hours>(chrono::abs(__d))),
__m_(chrono::duration_cast<chrono::minutes>(chrono::abs(__d) - hours())),
__s_(chrono::duration_cast<chrono::seconds>(chrono::abs(__d) - hours() - minutes())),
__f_(chrono::duration_cast<precision> (chrono::abs(__d) - hours() - minutes() - seconds()))
{}
__f_(chrono::duration_cast<precision>(chrono::abs(__d) - hours() - minutes() - seconds())) {}
_LIBCPP_HIDE_FROM_ABI constexpr bool is_negative() const noexcept { return __is_neg_; }
_LIBCPP_HIDE_FROM_ABI constexpr chrono::hours hours() const noexcept { return __h_; }
_LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes minutes() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds seconds() const noexcept { return __s_; }
_LIBCPP_HIDE_FROM_ABI constexpr precision subseconds() const noexcept { return __f_; }
_LIBCPP_HIDE_FROM_ABI constexpr bool is_negative() const noexcept { return __is_neg_; }
_LIBCPP_HIDE_FROM_ABI constexpr chrono::hours hours() const noexcept { return __h_; }
_LIBCPP_HIDE_FROM_ABI constexpr chrono::minutes minutes() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI constexpr chrono::seconds seconds() const noexcept { return __s_; }
_LIBCPP_HIDE_FROM_ABI constexpr precision subseconds() const noexcept { return __f_; }
_LIBCPP_HIDE_FROM_ABI constexpr precision to_duration() const noexcept
{
auto __dur = __h_ + __m_ + __s_ + __f_;
return __is_neg_ ? -__dur : __dur;
}
_LIBCPP_HIDE_FROM_ABI constexpr precision to_duration() const noexcept {
auto __dur = __h_ + __m_ + __s_ + __f_;
return __is_neg_ ? -__dur : __dur;
}
_LIBCPP_HIDE_FROM_ABI constexpr explicit operator precision() const noexcept { return to_duration(); }
_LIBCPP_HIDE_FROM_ABI constexpr explicit operator precision() const noexcept { return to_duration(); }
private:
bool __is_neg_;
chrono::hours __h_;
chrono::minutes __m_;
chrono::seconds __s_;
precision __f_;
bool __is_neg_;
chrono::hours __h_;
chrono::minutes __m_;
chrono::seconds __s_;
precision __f_;
};
_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(hh_mm_ss);
_LIBCPP_HIDE_FROM_ABI constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
_LIBCPP_HIDE_FROM_ABI constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
_LIBCPP_HIDE_FROM_ABI constexpr hours make12(const hours& __h) noexcept
{
if (__h == hours( 0)) return hours(12);
else if (__h <= hours(12)) return __h;
else return __h - hours(12);
_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_am(const hours& __h) noexcept {
return __h >= hours(0) && __h < hours(12);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_pm(const hours& __h) noexcept {
return __h >= hours(12) && __h < hours(24);
}
_LIBCPP_HIDE_FROM_ABI constexpr hours make24(const hours& __h, bool __is_pm) noexcept
{
if (__is_pm)
return __h == hours(12) ? __h : __h + hours(12);
else
return __h == hours(12) ? hours(0) : __h;
_LIBCPP_HIDE_FROM_ABI inline constexpr hours make12(const hours& __h) noexcept {
if (__h == hours(0))
return hours(12);
else if (__h <= hours(12))
return __h;
else
return __h - hours(12);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr hours make24(const hours& __h, bool __is_pm) noexcept {
if (__is_pm)
return __h == hours(12) ? __h : __h + hours(12);
else
return __h == hours(12) ? hours(0) : __h;
}
} // namespace chrono

View file

@ -20,8 +20,7 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
typedef steady_clock high_resolution_clock;

View file

@ -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_EXPERIMENTAL_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>
# include <__utility/private_constructor_tag.h>
# 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:
[[nodiscard]]
_LIBCPP_HIDE_FROM_ABI explicit constexpr leap_second(__private_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 _LIBCPP_HIDE_FROM_ABI constexpr sys_seconds date() const noexcept { return __date_; }
_LIBCPP_NODISCARD _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
} // namespace chrono
# endif //_LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // _LIBCPP___CHRONO_LEAP_SECOND_H

View file

@ -22,24 +22,20 @@
_LIBCPP_BEGIN_NAMESPACE_STD
inline namespace literals
{
inline namespace chrono_literals
{
_LIBCPP_HIDE_FROM_ABI constexpr chrono::day operator ""d(unsigned long long __d) noexcept
{
return chrono::day(static_cast<unsigned>(__d));
}
inline namespace literals {
inline namespace chrono_literals {
_LIBCPP_HIDE_FROM_ABI constexpr chrono::day operator""d(unsigned long long __d) noexcept {
return chrono::day(static_cast<unsigned>(__d));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::year operator ""y(unsigned long long __y) noexcept
{
return chrono::year(static_cast<int>(__y));
}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::year operator""y(unsigned long long __y) noexcept {
return chrono::year(static_cast<int>(__y));
}
} // namespace chrono_literals
} // namespace literals
namespace chrono { // hoist the literals into namespace std::chrono
using namespace literals::chrono_literals;
using namespace literals::chrono_literals;
} // namespace chrono
_LIBCPP_END_NAMESPACE_STD

View file

@ -0,0 +1,50 @@
// -*- 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_LOCAL_INFO_H
#define _LIBCPP___CHRONO_LOCAL_INFO_H
#include <version>
// Enable the contents of the header only when libc++ was built with experimental features enabled.
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
# include <__chrono/sys_info.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 {
struct local_info {
static constexpr int unique = 0;
static constexpr int nonexistent = 1;
static constexpr int ambiguous = 2;
int result;
sys_info first;
sys_info second;
};
} // namespace chrono
# endif // _LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // _LIBCPP___CHRONO_LOCAL_INFO_H

View file

@ -22,64 +22,76 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class month {
private:
unsigned char __m_;
unsigned char __m_;
public:
month() = default;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept : __m_(static_cast<unsigned char>(__val)) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept { ++__m_; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept { --__m_; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
_LIBCPP_HIDE_FROM_ABI constexpr month& operator+=(const months& __m1) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr month& operator-=(const months& __m1) noexcept;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_ >= 1 && __m_ <= 12; }
month() = default;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr month(unsigned __val) noexcept
: __m_(static_cast<unsigned char>(__val)) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr month& operator++() noexcept {
*this += months{1};
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr month operator++(int) noexcept {
month __tmp = *this;
++(*this);
return __tmp;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr month& operator--() noexcept {
*this -= months{1};
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr month operator--(int) noexcept {
month __tmp = *this;
--(*this);
return __tmp;
}
_LIBCPP_HIDE_FROM_ABI constexpr month& operator+=(const months& __m1) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr month& operator-=(const months& __m1) noexcept;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator unsigned() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_ >= 1 && __m_ <= 12; }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const month& __lhs, const month& __rhs) noexcept
{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept {
return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month& __lhs, const month& __rhs) noexcept {
return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month operator+ (const month& __lhs, const months& __rhs) noexcept
{
auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept {
return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month operator+ (const months& __lhs, const month& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
month operator- (const month& __lhs, const months& __rhs) noexcept
{ return __lhs + -__rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
months operator-(const month& __lhs, const month& __rhs) noexcept
{
auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
return months(__dm <= 11 ? __dm : __dm + 12);
_LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const month& __lhs, const months& __rhs) noexcept {
auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month& month::operator+=(const months& __dm) noexcept
{ *this = *this + __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month operator+(const months& __lhs, const month& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month& month::operator-=(const months& __dm) noexcept
{ *this = *this - __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month operator-(const month& __lhs, const months& __rhs) noexcept {
return __lhs + -__rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const month& __lhs, const month& __rhs) noexcept {
auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
return months(__dm <= 11 ? __dm : __dm + 12);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator+=(const months& __dm) noexcept {
*this = *this + __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr month& month::operator-=(const months& __dm) noexcept {
*this = *this - __dm;
return *this;
}
inline constexpr month January{1};
inline constexpr month February{2};

View file

@ -22,81 +22,80 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class month_weekday {
private:
chrono::month __m_;
chrono::weekday_indexed __wdi_;
chrono::month __m_;
chrono::weekday_indexed __wdi_;
public:
_LIBCPP_HIDE_FROM_ABI constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
: __m_{__mval}, __wdi_{__wdival} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdi_.ok(); }
_LIBCPP_HIDE_FROM_ABI constexpr month_weekday(const chrono::month& __mval,
const chrono::weekday_indexed& __wdival) noexcept
: __m_{__mval}, __wdi_{__wdival} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdi_.ok(); }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool
operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept {
return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
{ return !(__lhs == __rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday
operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept {
return month_weekday{__lhs, __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
{ return month_weekday{__lhs, __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept {
return month_weekday{month(__lhs), __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
{ return month_weekday{month(__lhs), __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
{ return month_weekday{__rhs, __lhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
{ return month_weekday{month(__rhs), __lhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday
operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept {
return month_weekday{__rhs, __lhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept {
return month_weekday{month(__rhs), __lhs};
}
class month_weekday_last {
chrono::month __m_;
chrono::weekday_last __wdl_;
public:
_LIBCPP_HIDE_FROM_ABI constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
: __m_{__mval}, __wdl_{__wdlval} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdl_.ok(); }
chrono::month __m_;
chrono::weekday_last __wdl_;
public:
_LIBCPP_HIDE_FROM_ABI constexpr month_weekday_last(const chrono::month& __mval,
const chrono::weekday_last& __wdlval) noexcept
: __m_{__mval}, __wdl_{__wdlval} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok() && __wdl_.ok(); }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool
operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept {
return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
{ return !(__lhs == __rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last
operator/(const month& __lhs, const weekday_last& __rhs) noexcept {
return month_weekday_last{__lhs, __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept {
return month_weekday_last{month(__lhs), __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
{ return month_weekday_last{__lhs, __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last
operator/(const weekday_last& __lhs, const month& __rhs) noexcept {
return month_weekday_last{__rhs, __lhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
{ return month_weekday_last{month(__lhs), __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
{ return month_weekday_last{__rhs, __lhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
{ return month_weekday_last{month(__rhs), __lhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept {
return month_weekday_last{month(__rhs), __lhs};
}
} // namespace chrono
_LIBCPP_END_NAMESPACE_STD

View file

@ -24,101 +24,105 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class month_day {
private:
chrono::month __m_;
chrono::day __d_;
chrono::month __m_;
chrono::day __d_;
public:
month_day() = default;
_LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
: __m_{__mval}, __d_{__dval} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; }
_LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
month_day() = default;
_LIBCPP_HIDE_FROM_ABI constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
: __m_{__mval}, __d_{__dval} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; }
_LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool month_day::ok() const noexcept
{
if (!__m_.ok()) return false;
const unsigned __dval = static_cast<unsigned>(__d_);
if (__dval < 1 || __dval > 31) return false;
if (__dval <= 29) return true;
// Now we've got either 30 or 31
const unsigned __mval = static_cast<unsigned>(__m_);
if (__mval == 2) return false;
if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
return __dval == 30;
_LIBCPP_HIDE_FROM_ABI inline constexpr bool month_day::ok() const noexcept {
if (!__m_.ok())
return false;
const unsigned __dval = static_cast<unsigned>(__d_);
if (__dval < 1 || __dval > 31)
return false;
if (__dval <= 29)
return true;
// Now we've got either 30 or 31
const unsigned __mval = static_cast<unsigned>(__m_);
if (__mval == 2)
return false;
if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
return __dval == 30;
return true;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept {
if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
return __c;
return __lhs.day() <=> __rhs.day();
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept {
return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_day operator/(const month& __lhs, const day& __rhs) noexcept
{ return month_day{__lhs, __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept {
if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
return __c;
return __lhs.day() <=> __rhs.day();
}
_LIBCPP_HIDE_FROM_ABI constexpr
month_day operator/(const day& __lhs, const month& __rhs) noexcept
{ return __rhs / __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, const day& __rhs) noexcept {
return month_day{__lhs, __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_day operator/(const month& __lhs, int __rhs) noexcept
{ return __lhs / day(__rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, const month& __rhs) noexcept {
return __rhs / __lhs;
}
_LIBCPP_HIDE_FROM_ABI constexpr
month_day operator/(int __lhs, const day& __rhs) noexcept
{ return month(__lhs) / __rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const month& __lhs, int __rhs) noexcept {
return __lhs / day(__rhs);
}
_LIBCPP_HIDE_FROM_ABI constexpr
month_day operator/(const day& __lhs, int __rhs) noexcept
{ return month(__rhs) / __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(int __lhs, const day& __rhs) noexcept {
return month(__lhs) / __rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, int __rhs) noexcept {
return month(__rhs) / __lhs;
}
class month_day_last {
private:
chrono::month __m_;
chrono::month __m_;
public:
_LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept
: __m_{__val} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok(); }
_LIBCPP_HIDE_FROM_ABI explicit constexpr month_day_last(const chrono::month& __val) noexcept : __m_{__val} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __m_.ok(); }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return __lhs.month() == __rhs.month(); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
return __lhs.month() <=> __rhs.month();
_LIBCPP_HIDE_FROM_ABI inline constexpr bool
operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
return __lhs.month() == __rhs.month();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_day_last operator/(const month& __lhs, last_spec) noexcept
{ return month_day_last{__lhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
return __lhs.month() <=> __rhs.month();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_day_last operator/(last_spec, const month& __rhs) noexcept
{ return month_day_last{__rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(const month& __lhs, last_spec) noexcept {
return month_day_last{__lhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_day_last operator/(int __lhs, last_spec) noexcept
{ return month_day_last{month(__lhs)}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, const month& __rhs) noexcept {
return month_day_last{__rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
month_day_last operator/(last_spec, int __rhs) noexcept
{ return month_day_last{month(__rhs)}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(int __lhs, last_spec) noexcept {
return month_day_last{month(__lhs)};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr month_day_last operator/(last_spec, int __rhs) noexcept {
return month_day_last{month(__rhs)};
}
} // namespace chrono

View file

@ -15,20 +15,23 @@
#include <__chrono/duration.h>
#include <__chrono/file_clock.h>
#include <__chrono/hh_mm_ss.h>
#include <__chrono/local_info.h>
#include <__chrono/month.h>
#include <__chrono/month_weekday.h>
#include <__chrono/monthday.h>
#include <__chrono/statically_widen.h>
#include <__chrono/sys_info.h>
#include <__chrono/system_clock.h>
#include <__chrono/weekday.h>
#include <__chrono/year.h>
#include <__chrono/year_month.h>
#include <__chrono/year_month_day.h>
#include <__chrono/year_month_weekday.h>
#include <__chrono/zoned_time.h>
#include <__concepts/same_as.h>
#include <__config>
#include <__format/format_functions.h>
#include <ostream>
#include <__fwd/ostream.h>
#include <ratio>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@ -42,11 +45,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono {
template <class _CharT, class _Traits, class _Duration>
requires(!treat_as_floating_point_v<typename _Duration::rep> && _Duration{1} < days{1})
_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_time<_Duration> __tp) {
operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_time<_Duration>& __tp) {
return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T}"), __tp);
}
template <class _CharT, class _Traits>
_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_days& __dp) {
return __os << year_month_day{__dp};
}
template <class _CharT, class _Traits, class _Duration>
_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const file_time<_Duration> __tp) {
@ -255,6 +265,54 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const hh_mm_ss<_Duration> __hms
return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%T}"), __hms);
}
# if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
template <class _CharT, class _Traits>
_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const sys_info& __info) {
// __info.abbrev is always std::basic_string<char>.
// Since these strings typically are short the conversion should be cheap.
std::basic_string<_CharT> __abbrev{__info.abbrev.begin(), __info.abbrev.end()};
return __os << std::format(
_LIBCPP_STATICALLY_WIDEN(_CharT, "[{:%F %T}, {:%F %T}) {:%T} {:%Q%q} \"{}\""),
__info.begin,
__info.end,
hh_mm_ss{__info.offset},
__info.save,
__abbrev);
}
template <class _CharT, class _Traits>
_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const local_info& __info) {
auto __result = [&]() -> basic_string<_CharT> {
switch (__info.result) {
case local_info::unique:
return _LIBCPP_STATICALLY_WIDEN(_CharT, "unique");
case local_info::nonexistent:
return _LIBCPP_STATICALLY_WIDEN(_CharT, "non-existent");
case local_info::ambiguous:
return _LIBCPP_STATICALLY_WIDEN(_CharT, "ambiguous");
default:
return std::format(_LIBCPP_STATICALLY_WIDEN(_CharT, "unspecified result ({})"), __info.result);
};
};
return __os << std::format(
_LIBCPP_STATICALLY_WIDEN(_CharT, "{}: {{{}, {}}}"), __result(), __info.first, __info.second);
}
# if !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
template <class _CharT, class _Traits, class _Duration, class _TimeZonePtr>
_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const zoned_time<_Duration, _TimeZonePtr>& __tp) {
return __os << std::format(__os.getloc(), _LIBCPP_STATICALLY_WIDEN(_CharT, "{:L%F %T %Z}"), __tp);
}
# endif
# endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
} // namespace chrono
#endif // if _LIBCPP_STD_VER >= 20

View file

@ -160,17 +160,17 @@ public:
private:
_LIBCPP_HIDE_FROM_ABI constexpr _ConstIterator
__parse_chrono_specs(_ConstIterator __begin, _ConstIterator __end, __flags __flags) {
_LIBCPP_ASSERT(__begin != __end,
"When called with an empty input the function will cause "
"undefined behavior by evaluating data not in the input");
_LIBCPP_ASSERT_INTERNAL(__begin != __end,
"When called with an empty input the function will cause "
"undefined behavior by evaluating data not in the input");
if (*__begin != _CharT('%') && *__begin != _CharT('}'))
std::__throw_format_error("Expected '%' or '}' in the chrono format-string");
std::__throw_format_error("The format specifier expects a '%' or a '}'");
do {
switch (*__begin) {
case _CharT('{'):
std::__throw_format_error("The chrono-specs contains a '{'");
std::__throw_format_error("The chrono specifiers contain a '{'");
case _CharT('}'):
return __begin;
@ -195,7 +195,7 @@ private:
__parse_conversion_spec(_ConstIterator& __begin, _ConstIterator __end, __flags __flags) {
++__begin;
if (__begin == __end)
std::__throw_format_error("End of input while parsing the modifier chrono conversion-spec");
std::__throw_format_error("End of input while parsing a conversion specifier");
switch (*__begin) {
case _CharT('n'):

View file

@ -20,20 +20,18 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
class _LIBCPP_TYPE_VIS steady_clock
{
class _LIBCPP_EXPORTED_FROM_ABI steady_clock {
public:
typedef nanoseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<steady_clock, duration> time_point;
static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = true;
typedef nanoseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<steady_clock, duration> time_point;
static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = true;
static time_point now() _NOEXCEPT;
static time_point now() _NOEXCEPT;
};
#endif

51
third_party/libcxx/__chrono/sys_info.h vendored Normal file
View file

@ -0,0 +1,51 @@
// -*- 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_SYS_INFO_H
#define _LIBCPP___CHRONO_SYS_INFO_H
#include <version>
// Enable the contents of the header only when libc++ was built with experimental features enabled.
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
# include <__chrono/duration.h>
# include <__chrono/system_clock.h>
# include <__chrono/time_point.h>
# include <__config>
# include <string>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
_LIBCPP_BEGIN_NAMESPACE_STD
# if _LIBCPP_STD_VER >= 20
namespace chrono {
struct sys_info {
sys_seconds begin;
sys_seconds end;
seconds offset;
minutes save;
string abbrev;
};
} // namespace chrono
# endif // _LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // _LIBCPP___CHRONO_SYS_INFO_H

View file

@ -21,21 +21,19 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class _LIBCPP_TYPE_VIS system_clock
{
class _LIBCPP_EXPORTED_FROM_ABI system_clock {
public:
typedef microseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<system_clock> time_point;
static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false;
typedef microseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<system_clock> time_point;
static _LIBCPP_CONSTEXPR_SINCE_CXX14 const bool is_steady = false;
static time_point now() _NOEXCEPT;
static time_t to_time_t (const time_point& __t) _NOEXCEPT;
static time_point from_time_t(time_t __t) _NOEXCEPT;
static time_point now() _NOEXCEPT;
static time_t to_time_t(const time_point& __t) _NOEXCEPT;
static time_point from_time_t(time_t __t) _NOEXCEPT;
};
#if _LIBCPP_STD_VER >= 20

View file

@ -28,128 +28,96 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
template <class _Clock, class _Duration = typename _Clock::duration>
class _LIBCPP_TEMPLATE_VIS time_point
{
static_assert(__is_duration<_Duration>::value,
"Second template parameter of time_point must be a std::chrono::duration");
class _LIBCPP_TEMPLATE_VIS time_point {
static_assert(__is_duration<_Duration>::value,
"Second template parameter of time_point must be a std::chrono::duration");
public:
typedef _Clock clock;
typedef _Duration duration;
typedef typename duration::rep rep;
typedef typename duration::period period;
typedef _Clock clock;
typedef _Duration duration;
typedef typename duration::rep rep;
typedef typename duration::period period;
private:
duration __d_;
duration __d_;
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point() : __d_(duration::zero()) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit time_point(const duration& __d) : __d_(__d) {}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point() : __d_(duration::zero()) {}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit time_point(const duration& __d) : __d_(__d) {}
// conversions
template <class _Duration2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
time_point(const time_point<clock, _Duration2>& __t,
typename enable_if
<
is_convertible<_Duration2, duration>::value
>::type* = nullptr)
: __d_(__t.time_since_epoch()) {}
// conversions
template <class _Duration2, __enable_if_t<is_convertible<_Duration2, duration>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point(const time_point<clock, _Duration2>& __t)
: __d_(__t.time_since_epoch()) {}
// observer
// observer
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14 duration time_since_epoch() const {return __d_;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 duration time_since_epoch() const { return __d_; }
// arithmetic
// arithmetic
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator+=(const duration& __d) {
__d_ += __d;
return *this;
}
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 time_point& operator-=(const duration& __d) {
__d_ -= __d;
return *this;
}
// special values
// special values
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT { return time_point(duration::min()); }
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT { return time_point(duration::max()); }
};
} // namespace chrono
template <class _Clock, class _Duration1, class _Duration2>
struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
chrono::time_point<_Clock, _Duration2> >
{
typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
struct _LIBCPP_TEMPLATE_VIS
common_type<chrono::time_point<_Clock, _Duration1>, chrono::time_point<_Clock, _Duration2> > {
typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
};
namespace chrono {
template <class _ToDuration, class _Clock, class _Duration>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
time_point<_Clock, _ToDuration>
time_point_cast(const time_point<_Clock, _Duration>& __t)
{
return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, _ToDuration>
time_point_cast(const time_point<_Clock, _Duration>& __t) {
return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
}
#if _LIBCPP_STD_VER >= 17
template <class _ToDuration, class _Clock, class _Duration>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
time_point<_Clock, _ToDuration>
>::type
floor(const time_point<_Clock, _Duration>& __t)
{
return time_point<_Clock, _ToDuration>{chrono::floor<_ToDuration>(__t.time_since_epoch())};
template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> floor(const time_point<_Clock, _Duration>& __t) {
return time_point<_Clock, _ToDuration>{chrono::floor<_ToDuration>(__t.time_since_epoch())};
}
template <class _ToDuration, class _Clock, class _Duration>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
time_point<_Clock, _ToDuration>
>::type
ceil(const time_point<_Clock, _Duration>& __t)
{
return time_point<_Clock, _ToDuration>{chrono::ceil<_ToDuration>(__t.time_since_epoch())};
template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> ceil(const time_point<_Clock, _Duration>& __t) {
return time_point<_Clock, _ToDuration>{chrono::ceil<_ToDuration>(__t.time_since_epoch())};
}
template <class _ToDuration, class _Clock, class _Duration>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
time_point<_Clock, _ToDuration>
>::type
round(const time_point<_Clock, _Duration>& __t)
{
return time_point<_Clock, _ToDuration>{chrono::round<_ToDuration>(__t.time_since_epoch())};
template <class _ToDuration, class _Clock, class _Duration, enable_if_t<__is_duration<_ToDuration>::value, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI constexpr time_point<_Clock, _ToDuration> round(const time_point<_Clock, _Duration>& __t) {
return time_point<_Clock, _ToDuration>{chrono::round<_ToDuration>(__t.time_since_epoch())};
}
template <class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
numeric_limits<_Rep>::is_signed,
duration<_Rep, _Period>
>::type
abs(duration<_Rep, _Period> __d)
{
return __d >= __d.zero() ? +__d : -__d;
template <class _Rep, class _Period, enable_if_t<numeric_limits<_Rep>::is_signed, int> = 0>
inline _LIBCPP_HIDE_FROM_ABI constexpr duration<_Rep, _Period> abs(duration<_Rep, _Period> __d) {
return __d >= __d.zero() ? +__d : -__d;
}
#endif // _LIBCPP_STD_VER >= 17
// time_point ==
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
bool
operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __lhs.time_since_epoch() == __rhs.time_since_epoch();
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) {
return __lhs.time_since_epoch() == __rhs.time_since_epoch();
}
#if _LIBCPP_STD_VER <= 17
@ -157,11 +125,9 @@ operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock,
// time_point !=
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
bool
operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return !(__lhs == __rhs);
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) {
return !(__lhs == __rhs);
}
#endif // _LIBCPP_STD_VER <= 17
@ -169,41 +135,33 @@ operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock,
// time_point <
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
bool
operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __lhs.time_since_epoch() < __rhs.time_since_epoch();
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) {
return __lhs.time_since_epoch() < __rhs.time_since_epoch();
}
// time_point >
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
bool
operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __rhs < __lhs;
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) {
return __rhs < __lhs;
}
// time_point <=
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
bool
operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return !(__rhs < __lhs);
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) {
return !(__rhs < __lhs);
}
// time_point >=
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
bool
operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return !(__lhs < __rhs);
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) {
return !(__lhs < __rhs);
}
#if _LIBCPP_STD_VER >= 20
@ -211,7 +169,7 @@ operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock,
template <class _Clock, class _Duration1, three_way_comparable_with<_Duration1> _Duration2>
_LIBCPP_HIDE_FROM_ABI constexpr auto
operator<=>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) {
return __lhs.time_since_epoch() <=> __rhs.time_since_epoch();
return __lhs.time_since_epoch() <=> __rhs.time_since_epoch();
}
#endif // _LIBCPP_STD_VER >= 20
@ -219,43 +177,38 @@ operator<=>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock
// time_point operator+(time_point x, duration y);
template <class _Clock, class _Duration1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
return _Tr (__lhs.time_since_epoch() + __rhs);
inline _LIBCPP_HIDE_FROM_ABI
_LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
return _Tr(__lhs.time_since_epoch() + __rhs);
}
// time_point operator+(duration x, time_point y);
template <class _Rep1, class _Period1, class _Clock, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __rhs + __lhs;
inline _LIBCPP_HIDE_FROM_ABI
_LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) {
return __rhs + __lhs;
}
// time_point operator-(time_point x, duration y);
template <class _Clock, class _Duration1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
return _Ret(__lhs.time_since_epoch() -__rhs);
inline _LIBCPP_HIDE_FROM_ABI
_LIBCPP_CONSTEXPR_SINCE_CXX14 time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) {
typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
return _Ret(__lhs.time_since_epoch() - __rhs);
}
// duration operator-(time_point x, time_point y);
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX14
typename common_type<_Duration1, _Duration2>::type
operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __lhs.time_since_epoch() - __rhs.time_since_epoch();
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename common_type<_Duration1, _Duration2>::type
operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) {
return __lhs.time_since_epoch() - __rhs.time_since_epoch();
}
} // namespace chrono

182
third_party/libcxx/__chrono/time_zone.h vendored Normal file
View file

@ -0,0 +1,182 @@
// -*- 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_TIME_ZONE_H
#define _LIBCPP___CHRONO_TIME_ZONE_H
#include <version>
// Enable the contents of the header only when libc++ was built with experimental features enabled.
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
# include <__chrono/calendar.h>
# include <__chrono/duration.h>
# include <__chrono/exception.h>
# include <__chrono/local_info.h>
# include <__chrono/sys_info.h>
# include <__chrono/system_clock.h>
# include <__compare/strong_order.h>
# include <__config>
# include <__memory/unique_ptr.h>
# include <__type_traits/common_type.h>
# include <string_view>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
_LIBCPP_PUSH_MACROS
# include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
namespace chrono {
enum class choose { earliest, latest };
class _LIBCPP_AVAILABILITY_TZDB time_zone {
_LIBCPP_HIDE_FROM_ABI time_zone() = default;
public:
class __impl; // public so it can be used by make_unique.
// The "constructor".
//
// The default constructor is private to avoid the constructor from being
// part of the ABI. Instead use an __ugly_named function as an ABI interface,
// since that gives us the ability to change it in the future.
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI static time_zone __create(unique_ptr<__impl>&& __p);
_LIBCPP_EXPORTED_FROM_ABI ~time_zone();
_LIBCPP_HIDE_FROM_ABI time_zone(time_zone&&) = default;
_LIBCPP_HIDE_FROM_ABI time_zone& operator=(time_zone&&) = default;
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name(); }
template <class _Duration>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_info get_info(const sys_time<_Duration>& __time) const {
return __get_info(chrono::time_point_cast<seconds>(__time));
}
template <class _Duration>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_info get_info(const local_time<_Duration>& __time) const {
return __get_info(chrono::time_point_cast<seconds>(__time));
}
// We don't apply nodiscard here since this function throws on many inputs,
// so it could be used as a validation.
template <class _Duration>
_LIBCPP_HIDE_FROM_ABI sys_time<common_type_t<_Duration, seconds>> to_sys(const local_time<_Duration>& __time) const {
local_info __info = get_info(__time);
switch (__info.result) {
case local_info::unique:
return sys_time<common_type_t<_Duration, seconds>>{__time.time_since_epoch() - __info.first.offset};
case local_info::nonexistent:
chrono::__throw_nonexistent_local_time(__time, __info);
case local_info::ambiguous:
chrono::__throw_ambiguous_local_time(__time, __info);
}
// TODO TZDB The Standard does not specify anything in these cases.
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
__info.result != -1, "cannot convert the local time; it would be before the minimum system clock value");
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
__info.result != -2, "cannot convert the local time; it would be after the maximum system clock value");
return {};
}
template <class _Duration>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time<common_type_t<_Duration, seconds>>
to_sys(const local_time<_Duration>& __time, choose __z) const {
local_info __info = get_info(__time);
switch (__info.result) {
case local_info::unique:
case local_info::nonexistent: // first and second are the same
return sys_time<common_type_t<_Duration, seconds>>{__time.time_since_epoch() - __info.first.offset};
case local_info::ambiguous:
switch (__z) {
case choose::earliest:
return sys_time<common_type_t<_Duration, seconds>>{__time.time_since_epoch() - __info.first.offset};
case choose::latest:
return sys_time<common_type_t<_Duration, seconds>>{__time.time_since_epoch() - __info.second.offset};
// Note a value out of bounds is not specified.
}
}
// TODO TZDB The standard does not specify anything in these cases.
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
__info.result != -1, "cannot convert the local time; it would be before the minimum system clock value");
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
__info.result != -2, "cannot convert the local time; it would be after the maximum system clock value");
return {};
}
template <class _Duration>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_time<common_type_t<_Duration, seconds>>
to_local(const sys_time<_Duration>& __time) const {
using _Dp = common_type_t<_Duration, seconds>;
sys_info __info = get_info(__time);
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
__info.offset >= chrono::seconds{0} || __time.time_since_epoch() >= _Dp::min() - __info.offset,
"cannot convert the system time; it would be before the minimum local clock value");
_LIBCPP_ASSERT_ARGUMENT_WITHIN_DOMAIN(
__info.offset <= chrono::seconds{0} || __time.time_since_epoch() <= _Dp::max() - __info.offset,
"cannot convert the system time; it would be after the maximum local clock value");
return local_time<_Dp>{__time.time_since_epoch() + __info.offset};
}
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const __impl& __implementation() const noexcept { return *__impl_; }
private:
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI string_view __name() const noexcept;
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI sys_info __get_info(sys_seconds __time) const;
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI local_info __get_info(local_seconds __time) const;
unique_ptr<__impl> __impl_;
};
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline bool
operator==(const time_zone& __x, const time_zone& __y) noexcept {
return __x.name() == __y.name();
}
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline strong_ordering
operator<=>(const time_zone& __x, const time_zone& __y) noexcept {
return __x.name() <=> __y.name();
}
} // namespace chrono
# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
// && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // _LIBCPP___CHRONO_TIME_ZONE_H

View file

@ -0,0 +1,79 @@
// -*- 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_TIME_ZONE_LINK_H
#define _LIBCPP___CHRONO_TIME_ZONE_LINK_H
#include <version>
// Enable the contents of the header only when libc++ was built with experimental features enabled.
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
# include <__compare/strong_order.h>
# include <__config>
# include <__utility/private_constructor_tag.h>
# include <string>
# include <string_view>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
_LIBCPP_PUSH_MACROS
# include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
namespace chrono {
class time_zone_link {
public:
[[nodiscard]]
_LIBCPP_HIDE_FROM_ABI explicit time_zone_link(__private_constructor_tag, string_view __name, string_view __target)
: __name_{__name}, __target_{__target} {}
_LIBCPP_HIDE_FROM_ABI time_zone_link(time_zone_link&&) = default;
_LIBCPP_HIDE_FROM_ABI time_zone_link& operator=(time_zone_link&&) = default;
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view name() const noexcept { return __name_; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI string_view target() const noexcept { return __target_; }
private:
string __name_;
// TODO TZDB instead of the name we can store the pointer to a zone. These
// pointers are immutable. This makes it possible to directly return a
// pointer in the time_zone in the 'locate_zone' function.
string __target_;
};
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline bool
operator==(const time_zone_link& __x, const time_zone_link& __y) noexcept {
return __x.name() == __y.name();
}
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline strong_ordering
operator<=>(const time_zone_link& __x, const time_zone_link& __y) noexcept {
return __x.name() <=> __y.name();
}
} // namespace chrono
# endif //_LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // _LIBCPP___CHRONO_TIME_ZONE_LINK_H

94
third_party/libcxx/__chrono/tzdb.h vendored Normal file
View file

@ -0,0 +1,94 @@
// -*- 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_TZDB_H
#define _LIBCPP___CHRONO_TZDB_H
#include <version>
// Enable the contents of the header only when libc++ was built with experimental features enabled.
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
# include <__algorithm/ranges_lower_bound.h>
# include <__chrono/leap_second.h>
# include <__chrono/time_zone.h>
# include <__chrono/time_zone_link.h>
# include <__config>
# include <string>
# include <vector>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
_LIBCPP_PUSH_MACROS
# include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
namespace chrono {
struct tzdb {
string version;
vector<time_zone> zones;
vector<time_zone_link> links;
vector<leap_second> leap_seconds;
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const time_zone* __locate_zone(string_view __name) const {
if (const time_zone* __result = __find_in_zone(__name))
return __result;
if (auto __it = ranges::lower_bound(links, __name, {}, &time_zone_link::name);
__it != links.end() && __it->name() == __name)
if (const time_zone* __result = __find_in_zone(__it->target()))
return __result;
return nullptr;
}
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const time_zone* locate_zone(string_view __name) const {
if (const time_zone* __result = __locate_zone(__name))
return __result;
std::__throw_runtime_error("tzdb: requested time zone not found");
}
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI const time_zone* current_zone() const {
return __current_zone();
}
private:
_LIBCPP_HIDE_FROM_ABI const time_zone* __find_in_zone(string_view __name) const noexcept {
if (auto __it = ranges::lower_bound(zones, __name, {}, &time_zone::name);
__it != zones.end() && __it->name() == __name)
return std::addressof(*__it);
return nullptr;
}
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const time_zone* __current_zone() const;
};
} // namespace chrono
# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
// && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // _LIBCPP___CHRONO_TZDB_H

108
third_party/libcxx/__chrono/tzdb_list.h vendored Normal file
View file

@ -0,0 +1,108 @@
// -*- 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_TZDB_LIST_H
#define _LIBCPP___CHRONO_TZDB_LIST_H
#include <version>
// Enable the contents of the header only when libc++ was built with experimental features enabled.
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
# include <__chrono/time_zone.h>
# include <__chrono/tzdb.h>
# include <__config>
# include <__fwd/string.h>
# include <forward_list>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
_LIBCPP_BEGIN_NAMESPACE_STD
# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
namespace chrono {
// TODO TZDB
// Libc++ recently switched to only export __ugly_names from the dylib.
// Since the library is still experimental the functions in this header
// should be adapted to this new style. The other tzdb headers should be
// evaluated too.
class _LIBCPP_AVAILABILITY_TZDB tzdb_list {
public:
class __impl; // public to allow construction in dylib
_LIBCPP_HIDE_FROM_ABI explicit tzdb_list(__impl* __p) : __impl_(__p) {
_LIBCPP_ASSERT_NON_NULL(__impl_ != nullptr, "initialized time_zone without a valid pimpl object");
}
_LIBCPP_EXPORTED_FROM_ABI ~tzdb_list();
tzdb_list(const tzdb_list&) = delete;
tzdb_list& operator=(const tzdb_list&) = delete;
using const_iterator = forward_list<tzdb>::const_iterator;
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const tzdb& front() const noexcept { return __front(); }
_LIBCPP_HIDE_FROM_ABI const_iterator erase_after(const_iterator __p) { return __erase_after(__p); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator begin() const noexcept { return __begin(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator end() const noexcept { return __end(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const noexcept { return __cbegin(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const_iterator cend() const noexcept { return __cend(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI __impl& __implementation() { return *__impl_; }
private:
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const tzdb& __front() const noexcept;
_LIBCPP_EXPORTED_FROM_ABI const_iterator __erase_after(const_iterator __p);
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __begin() const noexcept;
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __end() const noexcept;
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cbegin() const noexcept;
[[nodiscard]] _LIBCPP_EXPORTED_FROM_ABI const_iterator __cend() const noexcept;
__impl* __impl_;
};
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI tzdb_list& get_tzdb_list();
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline const tzdb& get_tzdb() {
return get_tzdb_list().front();
}
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline const time_zone* locate_zone(string_view __name) {
return get_tzdb().locate_zone(__name);
}
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_HIDE_FROM_ABI inline const time_zone* current_zone() {
return get_tzdb().current_zone();
}
_LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI const tzdb& reload_tzdb();
[[nodiscard]] _LIBCPP_AVAILABILITY_TZDB _LIBCPP_EXPORTED_FROM_ABI string remote_version();
} // namespace chrono
# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
// && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
_LIBCPP_END_NAMESPACE_STD
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // _LIBCPP___CHRONO_TZDB_LIST_H

View file

@ -24,157 +24,158 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class weekday_indexed;
class weekday_last;
class weekday {
private:
unsigned char __wd_;
_LIBCPP_HIDE_FROM_ABI static constexpr unsigned char __weekday_from_days(int __days) noexcept;
unsigned char __wd_;
_LIBCPP_HIDE_FROM_ABI static constexpr unsigned char __weekday_from_days(int __days) noexcept;
public:
weekday() = default;
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(unsigned __val) noexcept : __wd_(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday(const sys_days& __sysd) noexcept
: __wd_(__weekday_from_days(__sysd.time_since_epoch().count())) {}
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(unsigned __val) noexcept
: __wd_(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday(const sys_days& __sysd) noexcept
: __wd_(__weekday_from_days(__sysd.time_since_epoch().count())) {}
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr weekday(const local_days& __locd) noexcept
: __wd_(__weekday_from_days(__locd.time_since_epoch().count())) {}
: __wd_(__weekday_from_days(__locd.time_since_epoch().count())) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator++() noexcept { __wd_ = (__wd_ == 6 ? 0 : __wd_ + 1); return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator--() noexcept { __wd_ = (__wd_ == 0 ? 6 : __wd_ - 1); return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
_LIBCPP_HIDE_FROM_ABI constexpr weekday& operator+=(const days& __dd) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr weekday& operator-=(const days& __dd) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr unsigned c_encoding() const noexcept { return __wd_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator++() noexcept {
__wd_ = (__wd_ == 6 ? 0 : __wd_ + 1);
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator++(int) noexcept {
weekday __tmp = *this;
++(*this);
return __tmp;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday& operator--() noexcept {
__wd_ = (__wd_ == 0 ? 6 : __wd_ - 1);
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator--(int) noexcept {
weekday __tmp = *this;
--(*this);
return __tmp;
}
_LIBCPP_HIDE_FROM_ABI constexpr weekday& operator+=(const days& __dd) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr weekday& operator-=(const days& __dd) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr unsigned c_encoding() const noexcept { return __wd_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr unsigned iso_encoding() const noexcept { return __wd_ == 0u ? 7 : __wd_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __wd_ <= 6; }
_LIBCPP_HIDE_FROM_ABI constexpr weekday_indexed operator[](unsigned __index) const noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr weekday_last operator[](last_spec) const noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr weekday_indexed operator[](unsigned __index) const noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr weekday_last operator[](last_spec) const noexcept;
};
// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
_LIBCPP_HIDE_FROM_ABI inline constexpr
unsigned char weekday::__weekday_from_days(int __days) noexcept
{
return static_cast<unsigned char>(
static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
);
_LIBCPP_HIDE_FROM_ABI inline constexpr unsigned char weekday::__weekday_from_days(int __days) noexcept {
return static_cast<unsigned char>(static_cast<unsigned>(__days >= -4 ? (__days + 4) % 7 : (__days + 5) % 7 + 6));
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
{ return __lhs.c_encoding() == __rhs.c_encoding(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
{ return !(__lhs == __rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
{ return __lhs.c_encoding() < __rhs.c_encoding(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
{ return __rhs < __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
{ return !(__rhs < __lhs);}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
{ return !(__lhs < __rhs); }
_LIBCPP_HIDE_FROM_ABI constexpr
weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
{
auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
return weekday{static_cast<unsigned>(__mu - __yr * 7)};
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept {
return __lhs.c_encoding() == __rhs.c_encoding();
}
_LIBCPP_HIDE_FROM_ABI constexpr
weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI constexpr
weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
{ return __lhs + -__rhs; }
_LIBCPP_HIDE_FROM_ABI constexpr
days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
{
const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
return days{__wdu - __wk * 7};
// TODO(LLVM 20): Remove the escape hatch
# ifdef _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<(const weekday& __lhs, const weekday& __rhs) noexcept {
return __lhs.c_encoding() < __rhs.c_encoding();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
weekday& weekday::operator+=(const days& __dd) noexcept
{ *this = *this + __dd; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>(const weekday& __lhs, const weekday& __rhs) noexcept {
return __rhs < __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
weekday& weekday::operator-=(const days& __dd) noexcept
{ *this = *this - __dd; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept {
return !(__rhs < __lhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept {
return !(__lhs < __rhs);
}
# endif // _LIBCPP_ENABLE_REMOVED_WEEKDAY_RELATIONAL_OPERATORS
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept {
auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
return weekday{static_cast<unsigned>(__mu - __yr * 7)};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept {
return __lhs + -__rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept {
const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
const int __wk = (__wdu >= 0 ? __wdu : __wdu - 6) / 7;
return days{__wdu - __wk * 7};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept {
*this = *this + __dd;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept {
*this = *this - __dd;
return *this;
}
class weekday_indexed {
private:
chrono::weekday __wd_;
unsigned char __idx_;
chrono::weekday __wd_;
unsigned char __idx_;
public:
weekday_indexed() = default;
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept
: __wd_{__wdval}, __idx_(__idxval) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wd_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __idx_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __wd_.ok() && __idx_ >= 1 && __idx_ <= 5; }
weekday_indexed() = default;
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept
: __wd_{__wdval}, __idx_(__idxval) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wd_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __idx_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __wd_.ok() && __idx_ >= 1 && __idx_ <= 5; }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
{ return !(__lhs == __rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool
operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept {
return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index();
}
class weekday_last {
private:
chrono::weekday __wd_;
chrono::weekday __wd_;
public:
_LIBCPP_HIDE_FROM_ABI explicit constexpr weekday_last(const chrono::weekday& __val) noexcept
: __wd_{__val} {}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::weekday weekday() const noexcept { return __wd_; }
_LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept { return __wd_.ok(); }
_LIBCPP_HIDE_FROM_ABI explicit constexpr weekday_last(const chrono::weekday& __val) noexcept : __wd_{__val} {}
_LIBCPP_HIDE_FROM_ABI constexpr chrono::weekday weekday() const noexcept { return __wd_; }
_LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept { return __wd_.ok(); }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
{ return __lhs.weekday() == __rhs.weekday(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept {
return __lhs.weekday() == __rhs.weekday();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
{ return !(__lhs == __rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday_indexed weekday::operator[](unsigned __index) const noexcept {
return weekday_indexed{*this, __index};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr weekday_last weekday::operator[](last_spec) const noexcept {
return weekday_last{*this};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
inline constexpr weekday Sunday{0};
inline constexpr weekday Monday{1};
inline constexpr weekday Tuesday{2};
inline constexpr weekday Wednesday{3};
inline constexpr weekday Thursday{4};
inline constexpr weekday Friday{5};
inline constexpr weekday Saturday{6};
inline constexpr weekday Sunday{0};
inline constexpr weekday Monday{1};
inline constexpr weekday Tuesday{2};
inline constexpr weekday Wednesday{3};
inline constexpr weekday Thursday{4};
inline constexpr weekday Friday{5};
inline constexpr weekday Saturday{6};
} // namespace chrono

View file

@ -26,65 +26,81 @@ _LIBCPP_PUSH_MACROS
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class year {
private:
short __y_;
short __y_;
public:
year() = default;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr year(int __val) noexcept : __y_(static_cast<short>(__val)) {}
year() = default;
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr year(int __val) noexcept : __y_(static_cast<short>(__val)) {}
_LIBCPP_HIDE_FROM_ABI inline constexpr year& operator++() noexcept { ++__y_; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year& operator--() noexcept { --__y_; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }
_LIBCPP_HIDE_FROM_ABI constexpr year& operator+=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year& operator-=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator+() const noexcept { return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y_}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year& operator++() noexcept {
++__y_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator++(int) noexcept {
year __tmp = *this;
++(*this);
return __tmp;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year& operator--() noexcept {
--__y_;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator--(int) noexcept {
year __tmp = *this;
--(*this);
return __tmp;
}
_LIBCPP_HIDE_FROM_ABI constexpr year& operator+=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year& operator-=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator+() const noexcept { return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator-() const noexcept { return year{-__y_}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_leap() const noexcept { return __y_ % 4 == 0 && (__y_ % 100 != 0 || __y_ % 400 == 0); }
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator int() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
_LIBCPP_HIDE_FROM_ABI static inline constexpr year min() noexcept { return year{-32767}; }
_LIBCPP_HIDE_FROM_ABI static inline constexpr year max() noexcept { return year{ 32767}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_leap() const noexcept {
return __y_ % 4 == 0 && (__y_ % 100 != 0 || __y_ % 400 == 0);
}
_LIBCPP_HIDE_FROM_ABI explicit inline constexpr operator int() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
_LIBCPP_HIDE_FROM_ABI static inline constexpr year min() noexcept { return year{-32767}; }
_LIBCPP_HIDE_FROM_ABI static inline constexpr year max() noexcept { return year{32767}; }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year& __lhs, const year& __rhs) noexcept
{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year& __lhs, const year& __rhs) noexcept {
return static_cast<int>(__lhs) <=> static_cast<int>(__rhs);
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year& __lhs, const year& __rhs) noexcept {
return static_cast<int>(__lhs) == static_cast<int>(__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year operator+ (const year& __lhs, const years& __rhs) noexcept
{ return year(static_cast<int>(__lhs) + __rhs.count()); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year& __lhs, const year& __rhs) noexcept {
return static_cast<int>(__lhs) <=> static_cast<int>(__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year operator+ (const years& __lhs, const year& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const year& __lhs, const years& __rhs) noexcept {
return year(static_cast<int>(__lhs) + __rhs.count());
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year operator- (const year& __lhs, const years& __rhs) noexcept
{ return __lhs + -__rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator+(const years& __lhs, const year& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
years operator-(const year& __lhs, const year& __rhs) noexcept
{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year operator-(const year& __lhs, const years& __rhs) noexcept {
return __lhs + -__rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr years operator-(const year& __lhs, const year& __rhs) noexcept {
return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year& year::operator+=(const years& __dy) noexcept
{ *this = *this + __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year& year::operator+=(const years& __dy) noexcept {
*this = *this + __dy;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year& year::operator-=(const years& __dy) noexcept
{ *this = *this - __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year& year::operator-=(const years& __dy) noexcept {
*this = *this - __dy;
return *this;
}
_LIBCPP_HIDE_FROM_ABI constexpr bool year::ok() const noexcept {
static_assert(static_cast<int>(std::numeric_limits<decltype(__y_)>::max()) == static_cast<int>(max()));

View file

@ -24,73 +24,95 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class year_month {
chrono::year __y_;
chrono::month __m_;
chrono::year __y_;
chrono::month __m_;
public:
year_month() = default;
_LIBCPP_HIDE_FROM_ABI constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
: __y_{__yval}, __m_{__mval} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m_ += __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m_ -= __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y_ += __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y_ -= __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok(); }
year_month() = default;
_LIBCPP_HIDE_FROM_ABI constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
: __y_{__yval}, __m_{__mval} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator+=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& operator-=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok(); }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept {
if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
return __c;
return __lhs.month() <=> __rhs.month();
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, const month& __m) noexcept {
return year_month{__y, __m};
}
_LIBCPP_HIDE_FROM_ABI constexpr
year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
{
int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
__dmi = __dmi - __dy * 12 + 1;
return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator/(const year& __y, int __m) noexcept {
return year_month{__y, month(__m)};
}
_LIBCPP_HIDE_FROM_ABI constexpr
year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept {
return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month();
}
_LIBCPP_HIDE_FROM_ABI constexpr
year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
{ return (__lhs.year() + __rhs) / __lhs.month(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept {
if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
return __c;
return __lhs.month() <=> __rhs.month();
}
_LIBCPP_HIDE_FROM_ABI constexpr
year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept {
int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
const int __dy = (__dmi >= 0 ? __dmi : __dmi - 11) / 12;
__dmi = __dmi - __dy * 12 + 1;
return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
}
_LIBCPP_HIDE_FROM_ABI constexpr
months operator-(const year_month& __lhs, const year_month& __rhs) noexcept
{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI constexpr
year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
{ return __lhs + -__rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept {
return (__lhs.year() + __rhs) / __lhs.month();
}
_LIBCPP_HIDE_FROM_ABI constexpr
year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
{ return __lhs + -__rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept {
return (__lhs.year() - __rhs.year()) +
months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month()));
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept {
return __lhs + -__rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept {
return __lhs + -__rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator+=(const months& __dm) noexcept {
*this = *this + __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator-=(const months& __dm) noexcept {
*this = *this - __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator+=(const years& __dy) noexcept {
*this = *this + __dy;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator-=(const years& __dy) noexcept {
*this = *this - __dy;
return *this;
}
} // namespace chrono

View file

@ -31,271 +31,301 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class year_month_day_last;
class year_month_day {
private:
chrono::year __y_;
chrono::month __m_;
chrono::day __d_;
chrono::year __y_;
chrono::month __m_;
chrono::day __d_;
public:
year_month_day() = default;
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day(
const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
: __y_{__yval}, __m_{__mval}, __d_{__dval} {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day(const sys_days& __sysd) noexcept
: year_month_day(__from_days(__sysd.time_since_epoch())) {}
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr year_month_day(const local_days& __locd) noexcept
: year_month_day(__from_days(__locd.time_since_epoch())) {}
year_month_day() = default;
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day(
const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
: __y_{__yval}, __m_{__mval}, __d_{__dval} {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day(const sys_days& __sysd) noexcept
: year_month_day(__from_days(__sysd.time_since_epoch())) {}
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr year_month_day(const local_days& __locd) noexcept
: year_month_day(__from_days(__locd.time_since_epoch())) {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator+=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator-=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator+=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator-=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator+=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator-=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator+=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day& operator-=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day day() const noexcept { return __d_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept {
return local_days{__to_days()};
}
_LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr bool ok() const noexcept;
_LIBCPP_HIDE_FROM_ABI static constexpr year_month_day __from_days(days __d) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept;
_LIBCPP_HIDE_FROM_ABI static constexpr year_month_day __from_days(days __d) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept;
};
// https://howardhinnant.github.io/date_algorithms.html#civil_from_days
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day year_month_day::__from_days(days __d) noexcept
{
static_assert(numeric_limits<unsigned>::digits >= 18, "");
static_assert(numeric_limits<int>::digits >= 20 , "");
const int __z = __d.count() + 719468;
const int __era = (__z >= 0 ? __z : __z - 146096) / 146097;
const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096]
const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399]
const int __yr = static_cast<int>(__yoe) + __era * 400;
const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365]
const unsigned __mp = (5 * __doy + 2)/153; // [0, 11]
const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31]
const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12]
return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day year_month_day::__from_days(days __d) noexcept {
static_assert(numeric_limits<unsigned>::digits >= 18, "");
static_assert(numeric_limits<int>::digits >= 20, "");
const int __z = __d.count() + 719468;
const int __era = (__z >= 0 ? __z : __z - 146096) / 146097;
const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096]
const unsigned __yoe = (__doe - __doe / 1460 + __doe / 36524 - __doe / 146096) / 365; // [0, 399]
const int __yr = static_cast<int>(__yoe) + __era * 400;
const unsigned __doy = __doe - (365 * __yoe + __yoe / 4 - __yoe / 100); // [0, 365]
const unsigned __mp = (5 * __doy + 2) / 153; // [0, 11]
const unsigned __dy = __doy - (153 * __mp + 2) / 5 + 1; // [1, 31]
const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12]
return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
}
// https://howardhinnant.github.io/date_algorithms.html#days_from_civil
_LIBCPP_HIDE_FROM_ABI inline constexpr
days year_month_day::__to_days() const noexcept
{
static_assert(numeric_limits<unsigned>::digits >= 18, "");
static_assert(numeric_limits<int>::digits >= 20 , "");
_LIBCPP_HIDE_FROM_ABI inline constexpr days year_month_day::__to_days() const noexcept {
static_assert(numeric_limits<unsigned>::digits >= 18, "");
static_assert(numeric_limits<int>::digits >= 20, "");
const int __yr = static_cast<int>(__y_) - (__m_ <= February);
const unsigned __mth = static_cast<unsigned>(__m_);
const unsigned __dy = static_cast<unsigned>(__d_);
const int __yr = static_cast<int>(__y_) - (__m_ <= February);
const unsigned __mth = static_cast<unsigned>(__m_);
const unsigned __dy = static_cast<unsigned>(__d_);
const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399]
const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365]
const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096]
return days{__era * 146097 + static_cast<int>(__doe) - 719468};
const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399]
const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy - 1; // [0, 365]
const unsigned __doe = __yoe * 365 + __yoe / 4 - __yoe / 100 + __doy; // [0, 146096]
return days{__era * 146097 + static_cast<int>(__doe) - 719468};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool
operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept {
return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day();
}
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
operator<=>(const year_month_day& __lhs, const year_month_day& __rhs) noexcept {
if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
return __c;
if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
return __c;
return __lhs.day() <=> __rhs.day();
if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
return __c;
if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
return __c;
return __lhs.day() <=> __rhs.day();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept {
return year_month_day{__lhs.year(), __lhs.month(), __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
{ return __lhs / day(__rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const year_month& __lhs, int __rhs) noexcept {
return __lhs / day(__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
{ return __lhs / __rhs.month() / __rhs.day(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept {
return __lhs / __rhs.month() / __rhs.day();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
{ return year(__lhs) / __rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(int __lhs, const month_day& __rhs) noexcept {
return year(__lhs) / __rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
{ return __rhs / __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept {
return __rhs / __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
{ return year(__rhs) / __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day operator/(const month_day& __lhs, int __rhs) noexcept {
return year(__rhs) / __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day
operator+(const year_month_day& __lhs, const months& __rhs) noexcept {
return (__lhs.year() / __lhs.month() + __rhs) / __lhs.day();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day
operator+(const months& __lhs, const year_month_day& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day
operator-(const year_month_day& __lhs, const months& __rhs) noexcept {
return __lhs + -__rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
{ return __lhs + -__rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day
operator+(const year_month_day& __lhs, const years& __rhs) noexcept {
return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day
operator+(const years& __lhs, const year_month_day& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day
operator-(const year_month_day& __lhs, const years& __rhs) noexcept {
return __lhs + -__rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
{ return __lhs + -__rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept {
*this = *this + __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept {
*this = *this - __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept {
*this = *this + __dy;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept {
*this = *this - __dy;
return *this;
}
class year_month_day_last {
private:
chrono::year __y_;
chrono::month_day_last __mdl_;
chrono::year __y_;
chrono::month_day_last __mdl_;
public:
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
: __y_{__yval}, __mdl_{__mdlval} {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
: __y_{__yval}, __mdl_{__mdlval} {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const months& __m) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const months& __m) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const years& __y) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const years& __y) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const months& __m) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const months& __m) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator+=(const years& __y) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_day_last& operator-=(const years& __y) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __mdl_.month(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl_; }
_LIBCPP_HIDE_FROM_ABI constexpr chrono::day day() const noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; }
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __mdl_.ok(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __mdl_.month(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl_; }
_LIBCPP_HIDE_FROM_ABI constexpr chrono::day day() const noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept {
return sys_days{year() / month() / day()};
}
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept {
return local_days{year() / month() / day()};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __mdl_.ok(); }
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
chrono::day year_month_day_last::day() const noexcept
{
constexpr chrono::day __d[] =
{
chrono::day(31), chrono::day(28), chrono::day(31),
chrono::day(30), chrono::day(31), chrono::day(30),
chrono::day(31), chrono::day(31), chrono::day(30),
chrono::day(31), chrono::day(30), chrono::day(31)
};
return (month() != February || !__y_.is_leap()) && month().ok() ?
__d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::day year_month_day_last::day() const noexcept {
constexpr chrono::day __d[] = {
chrono::day(31),
chrono::day(28),
chrono::day(31),
chrono::day(30),
chrono::day(31),
chrono::day(30),
chrono::day(31),
chrono::day(31),
chrono::day(30),
chrono::day(31),
chrono::day(30),
chrono::day(31)};
return (month() != February || !__y_.is_leap()) && month().ok()
? __d[static_cast<unsigned>(month()) - 1]
: chrono::day{29};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return !(__lhs == __rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{
if (__lhs.year() < __rhs.year()) return true;
if (__lhs.year() > __rhs.year()) return false;
return __lhs.month_day_last() < __rhs.month_day_last();
_LIBCPP_HIDE_FROM_ABI inline constexpr bool
operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept {
return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return __rhs < __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
operator<=>(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept {
if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
return __c;
return __lhs.month_day_last() <=> __rhs.month_day_last();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return !(__rhs < __lhs);}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return !(__lhs < __rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
{ return year_month_day_last{__lhs, __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
{ return year_month_day_last{year{__lhs}, __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept {
return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last
operator/(const month_day_last& __lhs, const year& __rhs) noexcept
{ return __rhs / __lhs; }
operator/(const year& __lhs, const month_day_last& __rhs) noexcept {
return year_month_day_last{__lhs, __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
{ return year{__rhs} / __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept {
return year_month_day_last{year{__lhs}, __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last
operator/(const month_day_last& __lhs, const year& __rhs) noexcept {
return __rhs / __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
{ return (__lhs.year() / __lhs.month() + __rhs) / last; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept {
return year{__rhs} / __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last
operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept {
return (__lhs.year() / __lhs.month() + __rhs) / last;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
{ return __lhs + (-__rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last
operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last
operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept {
return __lhs + (-__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last
operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept {
return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
{ return __lhs + (-__rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last
operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last
operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept {
return __lhs + (-__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last&
year_month_day_last::operator+=(const months& __dm) noexcept {
*this = *this + __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last&
year_month_day_last::operator-=(const months& __dm) noexcept {
*this = *this - __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last&
year_month_day_last::operator+=(const years& __dy) noexcept {
*this = *this + __dy;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day_last&
year_month_day_last::operator-=(const years& __dy) noexcept {
*this = *this - __dy;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
: __y_{__ymdl.year()}, __m_{__ymdl.month()}, __d_{__ymdl.day()} {}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool year_month_day::ok() const noexcept
{
if (!__y_.ok() || !__m_.ok()) return false;
return chrono::day{1} <= __d_ && __d_ <= (__y_ / __m_ / last).day();
_LIBCPP_HIDE_FROM_ABI inline constexpr bool year_month_day::ok() const noexcept {
if (!__y_.ok() || !__m_.ok())
return false;
return chrono::day{1} <= __d_ && __d_ <= (__y_ / __m_ / last).day();
}
} // namespace chrono

View file

@ -31,220 +31,252 @@
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
namespace chrono {
class year_month_weekday {
chrono::year __y_;
chrono::month __m_;
chrono::weekday_indexed __wdi_;
chrono::year __y_;
chrono::month __m_;
chrono::weekday_indexed __wdi_;
public:
year_month_weekday() = default;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
const chrono::weekday_indexed& __wdival) noexcept
: __y_{__yval}, __m_{__mval}, __wdi_{__wdival} {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday(const sys_days& __sysd) noexcept
: year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
: year_month_weekday(__from_days(__locd.time_since_epoch())) {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator+=(const months&) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator-=(const months&) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator+=(const years&) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator-=(const years&) noexcept;
year_month_weekday() = default;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday(
const chrono::year& __yval, const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
: __y_{__yval}, __m_{__mval}, __wdi_{__wdival} {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday(const sys_days& __sysd) noexcept
: year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
: year_month_weekday(__from_days(__locd.time_since_epoch())) {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator+=(const months&) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator-=(const months&) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator+=(const years&) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday& operator-=(const years&) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wdi_.weekday(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __wdi_.index(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wdi_.weekday(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr unsigned index() const noexcept { return __wdi_.index(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept
{
if (!__y_.ok() || !__m_.ok() || !__wdi_.ok()) return false;
if (__wdi_.index() <= 4) return true;
auto __nth_weekday_day =
__wdi_.weekday() -
chrono::weekday{static_cast<sys_days>(__y_ / __m_ / 1)} +
days{(__wdi_.index() - 1) * 7 + 1};
return static_cast<unsigned>(__nth_weekday_day.count()) <=
static_cast<unsigned>((__y_ / __m_ / last).day());
}
_LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept {
return local_days{__to_days()};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept {
if (!__y_.ok() || !__m_.ok() || !__wdi_.ok())
return false;
if (__wdi_.index() <= 4)
return true;
auto __nth_weekday_day =
__wdi_.weekday() - chrono::weekday{static_cast<sys_days>(__y_ / __m_ / 1)} + days{(__wdi_.index() - 1) * 7 + 1};
return static_cast<unsigned>(__nth_weekday_day.count()) <= static_cast<unsigned>((__y_ / __m_ / last).day());
}
_LIBCPP_HIDE_FROM_ABI static constexpr year_month_weekday __from_days(days __d) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept;
_LIBCPP_HIDE_FROM_ABI static constexpr year_month_weekday __from_days(days __d) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept;
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday year_month_weekday::__from_days(days __d) noexcept
{
const sys_days __sysd{__d};
const chrono::weekday __wd = chrono::weekday(__sysd);
const year_month_day __ymd = year_month_day(__sysd);
return year_month_weekday{__ymd.year(), __ymd.month(),
__wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday year_month_weekday::__from_days(days __d) noexcept {
const sys_days __sysd{__d};
const chrono::weekday __wd = chrono::weekday(__sysd);
const year_month_day __ymd = year_month_day(__sysd);
return year_month_weekday{__ymd.year(), __ymd.month(), __wd[(static_cast<unsigned>(__ymd.day()) - 1) / 7 + 1]};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
days year_month_weekday::__to_days() const noexcept
{
const sys_days __sysd = sys_days(__y_/__m_/1);
return (__sysd + (__wdi_.weekday() - chrono::weekday(__sysd) + days{(__wdi_.index()-1)*7}))
.time_since_epoch();
_LIBCPP_HIDE_FROM_ABI inline constexpr days year_month_weekday::__to_days() const noexcept {
const sys_days __sysd = sys_days(__y_ / __m_ / 1);
return (__sysd + (__wdi_.weekday() - chrono::weekday(__sysd) + days{(__wdi_.index() - 1) * 7})).time_since_epoch();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool
operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept {
return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() &&
__lhs.weekday_indexed() == __rhs.weekday_indexed();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
{ return !(__lhs == __rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday
operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept {
return year_month_weekday{__lhs.year(), __lhs.month(), __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday
operator/(const year& __lhs, const month_weekday& __rhs) noexcept {
return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept {
return year(__lhs) / __rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
{ return year(__lhs) / __rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday
operator/(const month_weekday& __lhs, const year& __rhs) noexcept {
return __rhs / __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
{ return __rhs / __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept {
return year(__rhs) / __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
{ return year(__rhs) / __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday
operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept {
return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday
operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday
operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept {
return __lhs + (-__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday
operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept {
return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
{ return __lhs + (-__rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday
operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday
operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept {
return __lhs + (-__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
{ return __lhs + (-__rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept {
*this = *this + __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept {
*this = *this - __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept {
*this = *this + __dy;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept {
*this = *this - __dy;
return *this;
}
class year_month_weekday_last {
private:
chrono::year __y_;
chrono::month __m_;
chrono::weekday_last __wdl_;
chrono::year __y_;
chrono::month __m_;
chrono::weekday_last __wdl_;
public:
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
const chrono::weekday_last& __wdlval) noexcept
: __y_{__yval}, __m_{__mval}, __wdl_{__wdlval} {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last(
const chrono::year& __yval, const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
: __y_{__yval}, __m_{__mval}, __wdl_{__wdlval} {}
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wdl_.weekday(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok() && __wdl_.ok(); }
_LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept;
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::year year() const noexcept { return __y_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::month month() const noexcept { return __m_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday weekday() const noexcept { return __wdl_.weekday(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl_; }
_LIBCPP_HIDE_FROM_ABI inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
_LIBCPP_HIDE_FROM_ABI inline explicit constexpr operator local_days() const noexcept {
return local_days{__to_days()};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr bool ok() const noexcept { return __y_.ok() && __m_.ok() && __wdl_.ok(); }
_LIBCPP_HIDE_FROM_ABI constexpr days __to_days() const noexcept;
};
_LIBCPP_HIDE_FROM_ABI inline constexpr
days year_month_weekday_last::__to_days() const noexcept
{
const sys_days __last = sys_days{__y_/__m_/last};
return (__last - (chrono::weekday{__last} - __wdl_.weekday())).time_since_epoch();
_LIBCPP_HIDE_FROM_ABI inline constexpr days year_month_weekday_last::__to_days() const noexcept {
const sys_days __last = sys_days{__y_ / __m_ / last};
return (__last - (chrono::weekday{__last} - __wdl_.weekday())).time_since_epoch();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr bool
operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept {
return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
{ return !(__lhs == __rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept {
return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept {
return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator/(int __lhs, const month_weekday_last& __rhs) noexcept {
return year(__lhs) / __rhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept {
return __rhs / __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
{ return year(__lhs) / __rhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator/(const month_weekday_last& __lhs, int __rhs) noexcept {
return year(__rhs) / __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
{ return __rhs / __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept {
return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last();
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
{ return year(__rhs) / __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept {
return __lhs + (-__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept {
return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()};
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept {
return __rhs + __lhs;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
{ return __lhs + (-__rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last
operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept {
return __lhs + (-__rhs);
}
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
{ return __rhs + __lhs; }
_LIBCPP_HIDE_FROM_ABI inline constexpr
year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
{ return __lhs + (-__rhs); }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last&
year_month_weekday_last::operator+=(const months& __dm) noexcept {
*this = *this + __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last&
year_month_weekday_last::operator-=(const months& __dm) noexcept {
*this = *this - __dm;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last&
year_month_weekday_last::operator+=(const years& __dy) noexcept {
*this = *this + __dy;
return *this;
}
_LIBCPP_HIDE_FROM_ABI inline constexpr year_month_weekday_last&
year_month_weekday_last::operator-=(const years& __dy) noexcept {
*this = *this - __dy;
return *this;
}
} // namespace chrono

227
third_party/libcxx/__chrono/zoned_time.h vendored Normal file
View file

@ -0,0 +1,227 @@
// -*- 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_ZONED_TIME_H
#define _LIBCPP___CHRONO_ZONED_TIME_H
#include <version>
// Enable the contents of the header only when libc++ was built with experimental features enabled.
#if !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
# include <__chrono/calendar.h>
# include <__chrono/duration.h>
# include <__chrono/sys_info.h>
# include <__chrono/system_clock.h>
# include <__chrono/time_zone.h>
# include <__chrono/tzdb_list.h>
# include <__config>
# include <__fwd/string_view.h>
# include <__type_traits/common_type.h>
# include <__type_traits/conditional.h>
# include <__type_traits/remove_cvref.h>
# include <__utility/move.h>
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
_LIBCPP_PUSH_MACROS
# include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
# if _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM) && \
!defined(_LIBCPP_HAS_NO_LOCALIZATION)
namespace chrono {
template <class>
struct zoned_traits {};
template <>
struct zoned_traits<const time_zone*> {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static const time_zone* default_zone() { return chrono::locate_zone("UTC"); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI static const time_zone* locate_zone(string_view __name) {
return chrono::locate_zone(__name);
}
};
template <class _Duration, class _TimeZonePtr = const time_zone*>
class zoned_time {
// [time.zone.zonedtime.ctor]/2
static_assert(__is_duration<_Duration>::value,
"the program is ill-formed since _Duration is not a specialization of std::chrono::duration");
// The wording uses the constraints like
// constructible_from<zoned_time, decltype(__traits::locate_zone(string_view{}))>
// Using these constraints in the code causes the compiler to give an
// error that the constraint depends on itself. To avoid that issue use
// the fact it is possible to create this object from a _TimeZonePtr.
using __traits = zoned_traits<_TimeZonePtr>;
public:
using duration = common_type_t<_Duration, seconds>;
_LIBCPP_HIDE_FROM_ABI zoned_time()
requires requires { __traits::default_zone(); }
: __zone_{__traits::default_zone()}, __tp_{} {}
_LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time&) = default;
_LIBCPP_HIDE_FROM_ABI zoned_time& operator=(const zoned_time&) = default;
_LIBCPP_HIDE_FROM_ABI zoned_time(const sys_time<_Duration>& __tp)
requires requires { __traits::default_zone(); }
: __zone_{__traits::default_zone()}, __tp_{__tp} {}
_LIBCPP_HIDE_FROM_ABI explicit zoned_time(_TimeZonePtr __zone) : __zone_{std::move(__zone)}, __tp_{} {}
_LIBCPP_HIDE_FROM_ABI explicit zoned_time(string_view __name)
requires(requires { __traits::locate_zone(string_view{}); } &&
constructible_from<_TimeZonePtr, decltype(__traits::locate_zone(string_view{}))>)
: __zone_{__traits::locate_zone(__name)}, __tp_{} {}
template <class _Duration2>
_LIBCPP_HIDE_FROM_ABI zoned_time(const zoned_time<_Duration2, _TimeZonePtr>& __zt)
requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
: __zone_{__zt.get_time_zone()}, __tp_{__zt.get_sys_time()} {}
_LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const sys_time<_Duration>& __tp)
: __zone_{std::move(__zone)}, __tp_{__tp} {}
_LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const sys_time<_Duration>& __tp)
requires requires { _TimeZonePtr{__traits::locate_zone(string_view{})}; }
: zoned_time{__traits::locate_zone(__name), __tp} {}
_LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const local_time<_Duration>& __tp)
requires(is_convertible_v<decltype(std::declval<_TimeZonePtr&>() -> to_sys(local_time<_Duration>{})),
sys_time<duration>>)
: __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp)} {}
_LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const local_time<_Duration>& __tp)
requires(requires {
_TimeZonePtr{__traits::locate_zone(string_view{})};
} && is_convertible_v<decltype(std::declval<_TimeZonePtr&>() -> to_sys(local_time<_Duration>{})),
sys_time<duration>>)
: zoned_time{__traits::locate_zone(__name), __tp} {}
_LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const local_time<_Duration>& __tp, choose __c)
requires(is_convertible_v<
decltype(std::declval<_TimeZonePtr&>() -> to_sys(local_time<_Duration>{}, choose::earliest)),
sys_time<duration>>)
: __zone_{std::move(__zone)}, __tp_{__zone_->to_sys(__tp, __c)} {}
_LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const local_time<_Duration>& __tp, choose __c)
requires(requires {
_TimeZonePtr{__traits::locate_zone(string_view{})};
} && is_convertible_v<decltype(std::declval<_TimeZonePtr&>() -> to_sys(local_time<_Duration>{}, choose::earliest)),
sys_time<duration>>)
: zoned_time{__traits::locate_zone(__name), __tp, __c} {}
template <class _Duration2, class _TimeZonePtr2>
_LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
: __zone_{std::move(__zone)}, __tp_{__zt.get_sys_time()} {}
// per wording choose has no effect
template <class _Duration2, class _TimeZonePtr2>
_LIBCPP_HIDE_FROM_ABI zoned_time(_TimeZonePtr __zone, const zoned_time<_Duration2, _TimeZonePtr2>& __zt, choose)
requires is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>
: __zone_{std::move(__zone)}, __tp_{__zt.get_sys_time()} {}
template <class _Duration2, class _TimeZonePtr2>
_LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const zoned_time<_Duration2, _TimeZonePtr2>& __zt)
requires(requires {
_TimeZonePtr{__traits::locate_zone(string_view{})};
} && is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>)
: zoned_time{__traits::locate_zone(__name), __zt} {}
template <class _Duration2, class _TimeZonePtr2>
_LIBCPP_HIDE_FROM_ABI zoned_time(string_view __name, const zoned_time<_Duration2, _TimeZonePtr2>& __zt, choose __c)
requires(requires {
_TimeZonePtr{__traits::locate_zone(string_view{})};
} && is_convertible_v<sys_time<_Duration2>, sys_time<_Duration>>)
: zoned_time{__traits::locate_zone(__name), __zt, __c} {}
_LIBCPP_HIDE_FROM_ABI zoned_time& operator=(const sys_time<_Duration>& __tp) {
__tp_ = __tp;
return *this;
}
_LIBCPP_HIDE_FROM_ABI zoned_time& operator=(const local_time<_Duration>& __tp) {
// TODO TZDB This seems wrong.
// Assigning a non-existent or ambiguous time will throw and not satisfy
// the post condition. This seems quite odd; I constructed an object with
// choose::earliest and that choice is not respected.
// what did LEWG do with this.
// MSVC STL and libstdc++ behave the same
__tp_ = __zone_->to_sys(__tp);
return *this;
}
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI operator sys_time<duration>() const { return get_sys_time(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI explicit operator local_time<duration>() const { return get_local_time(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _TimeZonePtr get_time_zone() const { return __zone_; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI local_time<duration> get_local_time() const { return __zone_->to_local(__tp_); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_time<duration> get_sys_time() const { return __tp_; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI sys_info get_info() const { return __zone_->get_info(__tp_); }
private:
_TimeZonePtr __zone_;
sys_time<duration> __tp_;
};
zoned_time() -> zoned_time<seconds>;
template <class _Duration>
zoned_time(sys_time<_Duration>) -> zoned_time<common_type_t<_Duration, seconds>>;
template <class _TimeZonePtrOrName>
using __time_zone_representation =
conditional_t<is_convertible_v<_TimeZonePtrOrName, string_view>,
const time_zone*,
remove_cvref_t<_TimeZonePtrOrName>>;
template <class _TimeZonePtrOrName>
zoned_time(_TimeZonePtrOrName&&) -> zoned_time<seconds, __time_zone_representation<_TimeZonePtrOrName>>;
template <class _TimeZonePtrOrName, class _Duration>
zoned_time(_TimeZonePtrOrName&&, sys_time<_Duration>)
-> zoned_time<common_type_t<_Duration, seconds>, __time_zone_representation<_TimeZonePtrOrName>>;
template <class _TimeZonePtrOrName, class _Duration>
zoned_time(_TimeZonePtrOrName&&, local_time<_Duration>, choose = choose::earliest)
-> zoned_time<common_type_t<_Duration, seconds>, __time_zone_representation<_TimeZonePtrOrName>>;
template <class _Duration, class _TimeZonePtrOrName, class TimeZonePtr2>
zoned_time(_TimeZonePtrOrName&&, zoned_time<_Duration, TimeZonePtr2>, choose = choose::earliest)
-> zoned_time<common_type_t<_Duration, seconds>, __time_zone_representation<_TimeZonePtrOrName>>;
using zoned_seconds = zoned_time<seconds>;
template <class _Duration1, class _Duration2, class _TimeZonePtr>
_LIBCPP_HIDE_FROM_ABI bool
operator==(const zoned_time<_Duration1, _TimeZonePtr>& __lhs, const zoned_time<_Duration2, _TimeZonePtr>& __rhs) {
return __lhs.get_time_zone() == __rhs.get_time_zone() && __lhs.get_sys_time() == __rhs.get_sys_time();
}
} // namespace chrono
# endif // _LIBCPP_STD_VER >= 20 && !defined(_LIBCPP_HAS_NO_TIME_ZONE_DATABASE) && !defined(_LIBCPP_HAS_NO_FILESYSTEM)
// && !defined(_LIBCPP_HAS_NO_LOCALIZATION)
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // !defined(_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB)
#endif // _LIBCPP___CHRONO_ZONED_TIME_H