1*4d6fc14bSjoerg// -*- C++ -*- 2*4d6fc14bSjoerg//===---------------------------- chrono ----------------------------------===// 3*4d6fc14bSjoerg// 4*4d6fc14bSjoerg// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*4d6fc14bSjoerg// See https://llvm.org/LICENSE.txt for license information. 6*4d6fc14bSjoerg// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*4d6fc14bSjoerg// 8*4d6fc14bSjoerg//===----------------------------------------------------------------------===// 9*4d6fc14bSjoerg 10*4d6fc14bSjoerg#ifndef _LIBCPP_CHRONO 11*4d6fc14bSjoerg#define _LIBCPP_CHRONO 12*4d6fc14bSjoerg 13*4d6fc14bSjoerg/* 14*4d6fc14bSjoerg chrono synopsis 15*4d6fc14bSjoerg 16*4d6fc14bSjoergnamespace std 17*4d6fc14bSjoerg{ 18*4d6fc14bSjoergnamespace chrono 19*4d6fc14bSjoerg{ 20*4d6fc14bSjoerg 21*4d6fc14bSjoergtemplate <class ToDuration, class Rep, class Period> 22*4d6fc14bSjoergconstexpr 23*4d6fc14bSjoergToDuration 24*4d6fc14bSjoergduration_cast(const duration<Rep, Period>& fd); 25*4d6fc14bSjoerg 26*4d6fc14bSjoergtemplate <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; 27*4d6fc14bSjoerg 28*4d6fc14bSjoergtemplate <class Rep> inline constexpr bool treat_as_floating_point_v 29*4d6fc14bSjoerg = treat_as_floating_point<Rep>::value; // C++17 30*4d6fc14bSjoerg 31*4d6fc14bSjoergtemplate <class Rep> 32*4d6fc14bSjoergstruct duration_values 33*4d6fc14bSjoerg{ 34*4d6fc14bSjoergpublic: 35*4d6fc14bSjoerg static constexpr Rep zero(); // noexcept in C++20 36*4d6fc14bSjoerg static constexpr Rep max(); // noexcept in C++20 37*4d6fc14bSjoerg static constexpr Rep min(); // noexcept in C++20 38*4d6fc14bSjoerg}; 39*4d6fc14bSjoerg 40*4d6fc14bSjoerg// duration 41*4d6fc14bSjoerg 42*4d6fc14bSjoergtemplate <class Rep, class Period = ratio<1>> 43*4d6fc14bSjoergclass duration 44*4d6fc14bSjoerg{ 45*4d6fc14bSjoerg static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration"); 46*4d6fc14bSjoerg static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio"); 47*4d6fc14bSjoerg static_assert(Period::num > 0, "duration period must be positive"); 48*4d6fc14bSjoergpublic: 49*4d6fc14bSjoerg typedef Rep rep; 50*4d6fc14bSjoerg typedef typename _Period::type period; 51*4d6fc14bSjoerg 52*4d6fc14bSjoerg constexpr duration() = default; 53*4d6fc14bSjoerg template <class Rep2> 54*4d6fc14bSjoerg constexpr explicit duration(const Rep2& r, 55*4d6fc14bSjoerg typename enable_if 56*4d6fc14bSjoerg < 57*4d6fc14bSjoerg is_convertible<Rep2, rep>::value && 58*4d6fc14bSjoerg (treat_as_floating_point<rep>::value || 59*4d6fc14bSjoerg !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value) 60*4d6fc14bSjoerg >::type* = 0); 61*4d6fc14bSjoerg 62*4d6fc14bSjoerg // conversions 63*4d6fc14bSjoerg template <class Rep2, class Period2> 64*4d6fc14bSjoerg constexpr duration(const duration<Rep2, Period2>& d, 65*4d6fc14bSjoerg typename enable_if 66*4d6fc14bSjoerg < 67*4d6fc14bSjoerg treat_as_floating_point<rep>::value || 68*4d6fc14bSjoerg ratio_divide<Period2, period>::type::den == 1 69*4d6fc14bSjoerg >::type* = 0); 70*4d6fc14bSjoerg 71*4d6fc14bSjoerg // observer 72*4d6fc14bSjoerg 73*4d6fc14bSjoerg constexpr rep count() const; 74*4d6fc14bSjoerg 75*4d6fc14bSjoerg // arithmetic 76*4d6fc14bSjoerg 77*4d6fc14bSjoerg constexpr common_type<duration>::type operator+() const; 78*4d6fc14bSjoerg constexpr common_type<duration>::type operator-() const; 79*4d6fc14bSjoerg constexpr duration& operator++(); // constexpr in C++17 80*4d6fc14bSjoerg constexpr duration operator++(int); // constexpr in C++17 81*4d6fc14bSjoerg constexpr duration& operator--(); // constexpr in C++17 82*4d6fc14bSjoerg constexpr duration operator--(int); // constexpr in C++17 83*4d6fc14bSjoerg 84*4d6fc14bSjoerg constexpr duration& operator+=(const duration& d); // constexpr in C++17 85*4d6fc14bSjoerg constexpr duration& operator-=(const duration& d); // constexpr in C++17 86*4d6fc14bSjoerg 87*4d6fc14bSjoerg duration& operator*=(const rep& rhs); // constexpr in C++17 88*4d6fc14bSjoerg duration& operator/=(const rep& rhs); // constexpr in C++17 89*4d6fc14bSjoerg duration& operator%=(const rep& rhs); // constexpr in C++17 90*4d6fc14bSjoerg duration& operator%=(const duration& rhs); // constexpr in C++17 91*4d6fc14bSjoerg 92*4d6fc14bSjoerg // special values 93*4d6fc14bSjoerg 94*4d6fc14bSjoerg static constexpr duration zero(); // noexcept in C++20 95*4d6fc14bSjoerg static constexpr duration min(); // noexcept in C++20 96*4d6fc14bSjoerg static constexpr duration max(); // noexcept in C++20 97*4d6fc14bSjoerg}; 98*4d6fc14bSjoerg 99*4d6fc14bSjoergtypedef duration<long long, nano> nanoseconds; 100*4d6fc14bSjoergtypedef duration<long long, micro> microseconds; 101*4d6fc14bSjoergtypedef duration<long long, milli> milliseconds; 102*4d6fc14bSjoergtypedef duration<long long > seconds; 103*4d6fc14bSjoergtypedef duration< long, ratio< 60> > minutes; 104*4d6fc14bSjoergtypedef duration< long, ratio<3600> > hours; 105*4d6fc14bSjoerg 106*4d6fc14bSjoergtemplate <class Clock, class Duration = typename Clock::duration> 107*4d6fc14bSjoergclass time_point 108*4d6fc14bSjoerg{ 109*4d6fc14bSjoergpublic: 110*4d6fc14bSjoerg typedef Clock clock; 111*4d6fc14bSjoerg typedef Duration duration; 112*4d6fc14bSjoerg typedef typename duration::rep rep; 113*4d6fc14bSjoerg typedef typename duration::period period; 114*4d6fc14bSjoergprivate: 115*4d6fc14bSjoerg duration d_; // exposition only 116*4d6fc14bSjoerg 117*4d6fc14bSjoergpublic: 118*4d6fc14bSjoerg time_point(); // has value "epoch" // constexpr in C++14 119*4d6fc14bSjoerg explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 120*4d6fc14bSjoerg 121*4d6fc14bSjoerg // conversions 122*4d6fc14bSjoerg template <class Duration2> 123*4d6fc14bSjoerg time_point(const time_point<clock, Duration2>& t); // constexpr in C++14 124*4d6fc14bSjoerg 125*4d6fc14bSjoerg // observer 126*4d6fc14bSjoerg 127*4d6fc14bSjoerg duration time_since_epoch() const; // constexpr in C++14 128*4d6fc14bSjoerg 129*4d6fc14bSjoerg // arithmetic 130*4d6fc14bSjoerg 131*4d6fc14bSjoerg time_point& operator+=(const duration& d); // constexpr in C++17 132*4d6fc14bSjoerg time_point& operator-=(const duration& d); // constexpr in C++17 133*4d6fc14bSjoerg 134*4d6fc14bSjoerg // special values 135*4d6fc14bSjoerg 136*4d6fc14bSjoerg static constexpr time_point min(); // noexcept in C++20 137*4d6fc14bSjoerg static constexpr time_point max(); // noexcept in C++20 138*4d6fc14bSjoerg}; 139*4d6fc14bSjoerg 140*4d6fc14bSjoerg} // chrono 141*4d6fc14bSjoerg 142*4d6fc14bSjoerg// common_type traits 143*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 144*4d6fc14bSjoerg struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>; 145*4d6fc14bSjoerg 146*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Duration2> 147*4d6fc14bSjoerg struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>; 148*4d6fc14bSjoerg 149*4d6fc14bSjoergnamespace chrono { 150*4d6fc14bSjoerg 151*4d6fc14bSjoerg 152*4d6fc14bSjoergtemplate<class T> struct is_clock; // C++20 153*4d6fc14bSjoergtemplate<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20 154*4d6fc14bSjoerg 155*4d6fc14bSjoerg 156*4d6fc14bSjoerg// duration arithmetic 157*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 158*4d6fc14bSjoerg constexpr 159*4d6fc14bSjoerg typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 160*4d6fc14bSjoerg operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 161*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 162*4d6fc14bSjoerg constexpr 163*4d6fc14bSjoerg typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 164*4d6fc14bSjoerg operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 165*4d6fc14bSjoergtemplate <class Rep1, class Period, class Rep2> 166*4d6fc14bSjoerg constexpr 167*4d6fc14bSjoerg duration<typename common_type<Rep1, Rep2>::type, Period> 168*4d6fc14bSjoerg operator*(const duration<Rep1, Period>& d, const Rep2& s); 169*4d6fc14bSjoergtemplate <class Rep1, class Period, class Rep2> 170*4d6fc14bSjoerg constexpr 171*4d6fc14bSjoerg duration<typename common_type<Rep1, Rep2>::type, Period> 172*4d6fc14bSjoerg operator*(const Rep1& s, const duration<Rep2, Period>& d); 173*4d6fc14bSjoergtemplate <class Rep1, class Period, class Rep2> 174*4d6fc14bSjoerg constexpr 175*4d6fc14bSjoerg duration<typename common_type<Rep1, Rep2>::type, Period> 176*4d6fc14bSjoerg operator/(const duration<Rep1, Period>& d, const Rep2& s); 177*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 178*4d6fc14bSjoerg constexpr 179*4d6fc14bSjoerg typename common_type<Rep1, Rep2>::type 180*4d6fc14bSjoerg operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 181*4d6fc14bSjoerg 182*4d6fc14bSjoerg// duration comparisons 183*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 184*4d6fc14bSjoerg constexpr 185*4d6fc14bSjoerg bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 186*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 187*4d6fc14bSjoerg constexpr 188*4d6fc14bSjoerg bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 189*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 190*4d6fc14bSjoerg constexpr 191*4d6fc14bSjoerg bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 192*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 193*4d6fc14bSjoerg constexpr 194*4d6fc14bSjoerg bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 195*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 196*4d6fc14bSjoerg constexpr 197*4d6fc14bSjoerg bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 198*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Rep2, class Period2> 199*4d6fc14bSjoerg constexpr 200*4d6fc14bSjoerg bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 201*4d6fc14bSjoerg 202*4d6fc14bSjoerg// duration_cast 203*4d6fc14bSjoergtemplate <class ToDuration, class Rep, class Period> 204*4d6fc14bSjoerg ToDuration duration_cast(const duration<Rep, Period>& d); 205*4d6fc14bSjoerg 206*4d6fc14bSjoergtemplate <class ToDuration, class Rep, class Period> 207*4d6fc14bSjoerg constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17 208*4d6fc14bSjoergtemplate <class ToDuration, class Rep, class Period> 209*4d6fc14bSjoerg constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17 210*4d6fc14bSjoergtemplate <class ToDuration, class Rep, class Period> 211*4d6fc14bSjoerg constexpr ToDuration round(const duration<Rep, Period>& d); // C++17 212*4d6fc14bSjoerg 213*4d6fc14bSjoerg// duration I/O is elsewhere 214*4d6fc14bSjoerg 215*4d6fc14bSjoerg// time_point arithmetic (all constexpr in C++14) 216*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Rep2, class Period2> 217*4d6fc14bSjoerg time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 218*4d6fc14bSjoerg operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 219*4d6fc14bSjoergtemplate <class Rep1, class Period1, class Clock, class Duration2> 220*4d6fc14bSjoerg time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> 221*4d6fc14bSjoerg operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); 222*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Rep2, class Period2> 223*4d6fc14bSjoerg time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 224*4d6fc14bSjoerg operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 225*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Duration2> 226*4d6fc14bSjoerg typename common_type<Duration1, Duration2>::type 227*4d6fc14bSjoerg operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 228*4d6fc14bSjoerg 229*4d6fc14bSjoerg// time_point comparisons (all constexpr in C++14) 230*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Duration2> 231*4d6fc14bSjoerg bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 232*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Duration2> 233*4d6fc14bSjoerg bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 234*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Duration2> 235*4d6fc14bSjoerg bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 236*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Duration2> 237*4d6fc14bSjoerg bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 238*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Duration2> 239*4d6fc14bSjoerg bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 240*4d6fc14bSjoergtemplate <class Clock, class Duration1, class Duration2> 241*4d6fc14bSjoerg bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 242*4d6fc14bSjoerg 243*4d6fc14bSjoerg// time_point_cast (constexpr in C++14) 244*4d6fc14bSjoerg 245*4d6fc14bSjoergtemplate <class ToDuration, class Clock, class Duration> 246*4d6fc14bSjoerg time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); 247*4d6fc14bSjoerg 248*4d6fc14bSjoergtemplate <class ToDuration, class Clock, class Duration> 249*4d6fc14bSjoerg constexpr time_point<Clock, ToDuration> 250*4d6fc14bSjoerg floor(const time_point<Clock, Duration>& tp); // C++17 251*4d6fc14bSjoerg 252*4d6fc14bSjoergtemplate <class ToDuration, class Clock, class Duration> 253*4d6fc14bSjoerg constexpr time_point<Clock, ToDuration> 254*4d6fc14bSjoerg ceil(const time_point<Clock, Duration>& tp); // C++17 255*4d6fc14bSjoerg 256*4d6fc14bSjoergtemplate <class ToDuration, class Clock, class Duration> 257*4d6fc14bSjoerg constexpr time_point<Clock, ToDuration> 258*4d6fc14bSjoerg round(const time_point<Clock, Duration>& tp); // C++17 259*4d6fc14bSjoerg 260*4d6fc14bSjoergtemplate <class Rep, class Period> 261*4d6fc14bSjoerg constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17 262*4d6fc14bSjoerg 263*4d6fc14bSjoerg// Clocks 264*4d6fc14bSjoerg 265*4d6fc14bSjoergclass system_clock 266*4d6fc14bSjoerg{ 267*4d6fc14bSjoergpublic: 268*4d6fc14bSjoerg typedef microseconds duration; 269*4d6fc14bSjoerg typedef duration::rep rep; 270*4d6fc14bSjoerg typedef duration::period period; 271*4d6fc14bSjoerg typedef chrono::time_point<system_clock> time_point; 272*4d6fc14bSjoerg static const bool is_steady = false; // constexpr in C++14 273*4d6fc14bSjoerg 274*4d6fc14bSjoerg static time_point now() noexcept; 275*4d6fc14bSjoerg static time_t to_time_t (const time_point& __t) noexcept; 276*4d6fc14bSjoerg static time_point from_time_t(time_t __t) noexcept; 277*4d6fc14bSjoerg}; 278*4d6fc14bSjoerg 279*4d6fc14bSjoergtemplate <class Duration> 280*4d6fc14bSjoerg using sys_time = time_point<system_clock, Duration>; // C++20 281*4d6fc14bSjoergusing sys_seconds = sys_time<seconds>; // C++20 282*4d6fc14bSjoergusing sys_days = sys_time<days>; // C++20 283*4d6fc14bSjoerg 284*4d6fc14bSjoergclass utc_clock; // C++20 285*4d6fc14bSjoerg 286*4d6fc14bSjoergtemplate <class Duration> 287*4d6fc14bSjoerg using utc_time = time_point<utc_clock, Duration>; // C++20 288*4d6fc14bSjoergusing utc_seconds = utc_time<seconds>; // C++20 289*4d6fc14bSjoerg 290*4d6fc14bSjoergclass tai_clock; // C++20 291*4d6fc14bSjoerg 292*4d6fc14bSjoergtemplate <class Duration> 293*4d6fc14bSjoerg using tai_time = time_point<tai_clock, Duration>; // C++20 294*4d6fc14bSjoergusing tai_seconds = tai_time<seconds>; // C++20 295*4d6fc14bSjoerg 296*4d6fc14bSjoergclass file_clock; // C++20 297*4d6fc14bSjoerg 298*4d6fc14bSjoergtemplate<class Duration> 299*4d6fc14bSjoerg using file_time = time_point<file_clock, Duration>; // C++20 300*4d6fc14bSjoerg 301*4d6fc14bSjoergclass steady_clock 302*4d6fc14bSjoerg{ 303*4d6fc14bSjoergpublic: 304*4d6fc14bSjoerg typedef nanoseconds duration; 305*4d6fc14bSjoerg typedef duration::rep rep; 306*4d6fc14bSjoerg typedef duration::period period; 307*4d6fc14bSjoerg typedef chrono::time_point<steady_clock, duration> time_point; 308*4d6fc14bSjoerg static const bool is_steady = true; // constexpr in C++14 309*4d6fc14bSjoerg 310*4d6fc14bSjoerg static time_point now() noexcept; 311*4d6fc14bSjoerg}; 312*4d6fc14bSjoerg 313*4d6fc14bSjoergtypedef steady_clock high_resolution_clock; 314*4d6fc14bSjoerg 315*4d6fc14bSjoerg// 25.7.8, local time // C++20 316*4d6fc14bSjoergstruct local_t {}; 317*4d6fc14bSjoergtemplate<class Duration> 318*4d6fc14bSjoerg using local_time = time_point<local_t, Duration>; 319*4d6fc14bSjoergusing local_seconds = local_time<seconds>; 320*4d6fc14bSjoergusing local_days = local_time<days>; 321*4d6fc14bSjoerg 322*4d6fc14bSjoerg// 25.7.9, time_point conversions template<class DestClock, class SourceClock> // C++20 323*4d6fc14bSjoergstruct clock_time_conversion; 324*4d6fc14bSjoerg 325*4d6fc14bSjoergtemplate<class DestClock, class SourceClock, class Duration> 326*4d6fc14bSjoerg auto clock_cast(const time_point<SourceClock, Duration>& t); 327*4d6fc14bSjoerg 328*4d6fc14bSjoerg// 25.8.2, class last_spec // C++20 329*4d6fc14bSjoergstruct last_spec; 330*4d6fc14bSjoerg 331*4d6fc14bSjoerg// 25.8.3, class day // C++20 332*4d6fc14bSjoerg 333*4d6fc14bSjoergclass day; 334*4d6fc14bSjoergconstexpr bool operator==(const day& x, const day& y) noexcept; 335*4d6fc14bSjoergconstexpr bool operator!=(const day& x, const day& y) noexcept; 336*4d6fc14bSjoergconstexpr bool operator< (const day& x, const day& y) noexcept; 337*4d6fc14bSjoergconstexpr bool operator> (const day& x, const day& y) noexcept; 338*4d6fc14bSjoergconstexpr bool operator<=(const day& x, const day& y) noexcept; 339*4d6fc14bSjoergconstexpr bool operator>=(const day& x, const day& y) noexcept; 340*4d6fc14bSjoergconstexpr day operator+(const day& x, const days& y) noexcept; 341*4d6fc14bSjoergconstexpr day operator+(const days& x, const day& y) noexcept; 342*4d6fc14bSjoergconstexpr day operator-(const day& x, const days& y) noexcept; 343*4d6fc14bSjoergconstexpr days operator-(const day& x, const day& y) noexcept; 344*4d6fc14bSjoerg 345*4d6fc14bSjoerg// 25.8.4, class month // C++20 346*4d6fc14bSjoergclass month; 347*4d6fc14bSjoergconstexpr bool operator==(const month& x, const month& y) noexcept; 348*4d6fc14bSjoergconstexpr bool operator!=(const month& x, const month& y) noexcept; 349*4d6fc14bSjoergconstexpr bool operator< (const month& x, const month& y) noexcept; 350*4d6fc14bSjoergconstexpr bool operator> (const month& x, const month& y) noexcept; 351*4d6fc14bSjoergconstexpr bool operator<=(const month& x, const month& y) noexcept; 352*4d6fc14bSjoergconstexpr bool operator>=(const month& x, const month& y) noexcept; 353*4d6fc14bSjoergconstexpr month operator+(const month& x, const months& y) noexcept; 354*4d6fc14bSjoergconstexpr month operator+(const months& x, const month& y) noexcept; 355*4d6fc14bSjoergconstexpr month operator-(const month& x, const months& y) noexcept; 356*4d6fc14bSjoergconstexpr months operator-(const month& x, const month& y) noexcept; 357*4d6fc14bSjoerg 358*4d6fc14bSjoerg// 25.8.5, class year // C++20 359*4d6fc14bSjoergclass year; 360*4d6fc14bSjoergconstexpr bool operator==(const year& x, const year& y) noexcept; 361*4d6fc14bSjoergconstexpr bool operator!=(const year& x, const year& y) noexcept; 362*4d6fc14bSjoergconstexpr bool operator< (const year& x, const year& y) noexcept; 363*4d6fc14bSjoergconstexpr bool operator> (const year& x, const year& y) noexcept; 364*4d6fc14bSjoergconstexpr bool operator<=(const year& x, const year& y) noexcept; 365*4d6fc14bSjoergconstexpr bool operator>=(const year& x, const year& y) noexcept; 366*4d6fc14bSjoergconstexpr year operator+(const year& x, const years& y) noexcept; 367*4d6fc14bSjoergconstexpr year operator+(const years& x, const year& y) noexcept; 368*4d6fc14bSjoergconstexpr year operator-(const year& x, const years& y) noexcept; 369*4d6fc14bSjoergconstexpr years operator-(const year& x, const year& y) noexcept; 370*4d6fc14bSjoerg 371*4d6fc14bSjoerg// 25.8.6, class weekday // C++20 372*4d6fc14bSjoergclass weekday; 373*4d6fc14bSjoerg 374*4d6fc14bSjoergconstexpr bool operator==(const weekday& x, const weekday& y) noexcept; 375*4d6fc14bSjoergconstexpr bool operator!=(const weekday& x, const weekday& y) noexcept; 376*4d6fc14bSjoergconstexpr weekday operator+(const weekday& x, const days& y) noexcept; 377*4d6fc14bSjoergconstexpr weekday operator+(const days& x, const weekday& y) noexcept; 378*4d6fc14bSjoergconstexpr weekday operator-(const weekday& x, const days& y) noexcept; 379*4d6fc14bSjoergconstexpr days operator-(const weekday& x, const weekday& y) noexcept; 380*4d6fc14bSjoerg 381*4d6fc14bSjoerg// 25.8.7, class weekday_indexed // C++20 382*4d6fc14bSjoerg 383*4d6fc14bSjoergclass weekday_indexed; 384*4d6fc14bSjoergconstexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; 385*4d6fc14bSjoergconstexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept; 386*4d6fc14bSjoerg 387*4d6fc14bSjoerg// 25.8.8, class weekday_last // C++20 388*4d6fc14bSjoergclass weekday_last; 389*4d6fc14bSjoerg 390*4d6fc14bSjoergconstexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept; 391*4d6fc14bSjoergconstexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept; 392*4d6fc14bSjoerg 393*4d6fc14bSjoerg// 25.8.9, class month_day // C++20 394*4d6fc14bSjoergclass month_day; 395*4d6fc14bSjoerg 396*4d6fc14bSjoergconstexpr bool operator==(const month_day& x, const month_day& y) noexcept; 397*4d6fc14bSjoergconstexpr bool operator!=(const month_day& x, const month_day& y) noexcept; 398*4d6fc14bSjoergconstexpr bool operator< (const month_day& x, const month_day& y) noexcept; 399*4d6fc14bSjoergconstexpr bool operator> (const month_day& x, const month_day& y) noexcept; 400*4d6fc14bSjoergconstexpr bool operator<=(const month_day& x, const month_day& y) noexcept; 401*4d6fc14bSjoergconstexpr bool operator>=(const month_day& x, const month_day& y) noexcept; 402*4d6fc14bSjoerg 403*4d6fc14bSjoerg 404*4d6fc14bSjoerg// 25.8.10, class month_day_last // C++20 405*4d6fc14bSjoergclass month_day_last; 406*4d6fc14bSjoerg 407*4d6fc14bSjoergconstexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept; 408*4d6fc14bSjoergconstexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept; 409*4d6fc14bSjoergconstexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept; 410*4d6fc14bSjoergconstexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept; 411*4d6fc14bSjoergconstexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept; 412*4d6fc14bSjoergconstexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept; 413*4d6fc14bSjoerg 414*4d6fc14bSjoerg// 25.8.11, class month_weekday // C++20 415*4d6fc14bSjoergclass month_weekday; 416*4d6fc14bSjoerg 417*4d6fc14bSjoergconstexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; 418*4d6fc14bSjoergconstexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept; 419*4d6fc14bSjoerg 420*4d6fc14bSjoerg// 25.8.12, class month_weekday_last // C++20 421*4d6fc14bSjoergclass month_weekday_last; 422*4d6fc14bSjoerg 423*4d6fc14bSjoergconstexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; 424*4d6fc14bSjoergconstexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept; 425*4d6fc14bSjoerg 426*4d6fc14bSjoerg 427*4d6fc14bSjoerg// 25.8.13, class year_month // C++20 428*4d6fc14bSjoergclass year_month; 429*4d6fc14bSjoerg 430*4d6fc14bSjoergconstexpr bool operator==(const year_month& x, const year_month& y) noexcept; 431*4d6fc14bSjoergconstexpr bool operator!=(const year_month& x, const year_month& y) noexcept; 432*4d6fc14bSjoergconstexpr bool operator< (const year_month& x, const year_month& y) noexcept; 433*4d6fc14bSjoergconstexpr bool operator> (const year_month& x, const year_month& y) noexcept; 434*4d6fc14bSjoergconstexpr bool operator<=(const year_month& x, const year_month& y) noexcept; 435*4d6fc14bSjoergconstexpr bool operator>=(const year_month& x, const year_month& y) noexcept; 436*4d6fc14bSjoerg 437*4d6fc14bSjoergconstexpr year_month operator+(const year_month& ym, const months& dm) noexcept; 438*4d6fc14bSjoergconstexpr year_month operator+(const months& dm, const year_month& ym) noexcept; 439*4d6fc14bSjoergconstexpr year_month operator-(const year_month& ym, const months& dm) noexcept; 440*4d6fc14bSjoergconstexpr months operator-(const year_month& x, const year_month& y) noexcept; 441*4d6fc14bSjoergconstexpr year_month operator+(const year_month& ym, const years& dy) noexcept; 442*4d6fc14bSjoergconstexpr year_month operator+(const years& dy, const year_month& ym) noexcept; 443*4d6fc14bSjoergconstexpr year_month operator-(const year_month& ym, const years& dy) noexcept; 444*4d6fc14bSjoerg 445*4d6fc14bSjoerg// 25.8.14, class year_month_day class // C++20 446*4d6fc14bSjoergyear_month_day; 447*4d6fc14bSjoerg 448*4d6fc14bSjoergconstexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept; 449*4d6fc14bSjoergconstexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept; 450*4d6fc14bSjoergconstexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept; 451*4d6fc14bSjoergconstexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept; 452*4d6fc14bSjoergconstexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept; 453*4d6fc14bSjoergconstexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept; 454*4d6fc14bSjoerg 455*4d6fc14bSjoergconstexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; 456*4d6fc14bSjoergconstexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; 457*4d6fc14bSjoergconstexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; 458*4d6fc14bSjoergconstexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; 459*4d6fc14bSjoergconstexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; 460*4d6fc14bSjoergconstexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; 461*4d6fc14bSjoerg 462*4d6fc14bSjoerg 463*4d6fc14bSjoerg// 25.8.15, class year_month_day_last // C++20 464*4d6fc14bSjoergclass year_month_day_last; 465*4d6fc14bSjoerg 466*4d6fc14bSjoergconstexpr bool operator==(const year_month_day_last& x, 467*4d6fc14bSjoerg const year_month_day_last& y) noexcept; 468*4d6fc14bSjoergconstexpr bool operator!=(const year_month_day_last& x, 469*4d6fc14bSjoerg const year_month_day_last& y) noexcept; 470*4d6fc14bSjoergconstexpr bool operator< (const year_month_day_last& x, 471*4d6fc14bSjoerg const year_month_day_last& y) noexcept; 472*4d6fc14bSjoergconstexpr bool operator> (const year_month_day_last& x, 473*4d6fc14bSjoerg const year_month_day_last& y) noexcept; 474*4d6fc14bSjoergconstexpr bool operator<=(const year_month_day_last& x, 475*4d6fc14bSjoerg const year_month_day_last& y) noexcept; 476*4d6fc14bSjoergconstexpr bool operator>=(const year_month_day_last& x, 477*4d6fc14bSjoerg const year_month_day_last& y) noexcept; 478*4d6fc14bSjoerg 479*4d6fc14bSjoergconstexpr year_month_day_last 480*4d6fc14bSjoerg operator+(const year_month_day_last& ymdl, const months& dm) noexcept; 481*4d6fc14bSjoergconstexpr year_month_day_last 482*4d6fc14bSjoerg operator+(const months& dm, const year_month_day_last& ymdl) noexcept; 483*4d6fc14bSjoergconstexpr year_month_day_last 484*4d6fc14bSjoerg operator+(const year_month_day_last& ymdl, const years& dy) noexcept; 485*4d6fc14bSjoergconstexpr year_month_day_last 486*4d6fc14bSjoerg operator+(const years& dy, const year_month_day_last& ymdl) noexcept; 487*4d6fc14bSjoergconstexpr year_month_day_last 488*4d6fc14bSjoerg operator-(const year_month_day_last& ymdl, const months& dm) noexcept; 489*4d6fc14bSjoergconstexpr year_month_day_last 490*4d6fc14bSjoerg operator-(const year_month_day_last& ymdl, const years& dy) noexcept; 491*4d6fc14bSjoerg 492*4d6fc14bSjoerg// 25.8.16, class year_month_weekday // C++20 493*4d6fc14bSjoergclass year_month_weekday; 494*4d6fc14bSjoerg 495*4d6fc14bSjoergconstexpr bool operator==(const year_month_weekday& x, 496*4d6fc14bSjoerg const year_month_weekday& y) noexcept; 497*4d6fc14bSjoergconstexpr bool operator!=(const year_month_weekday& x, 498*4d6fc14bSjoerg const year_month_weekday& y) noexcept; 499*4d6fc14bSjoerg 500*4d6fc14bSjoergconstexpr year_month_weekday 501*4d6fc14bSjoerg operator+(const year_month_weekday& ymwd, const months& dm) noexcept; 502*4d6fc14bSjoergconstexpr year_month_weekday 503*4d6fc14bSjoerg operator+(const months& dm, const year_month_weekday& ymwd) noexcept; 504*4d6fc14bSjoergconstexpr year_month_weekday 505*4d6fc14bSjoerg operator+(const year_month_weekday& ymwd, const years& dy) noexcept; 506*4d6fc14bSjoergconstexpr year_month_weekday 507*4d6fc14bSjoerg operator+(const years& dy, const year_month_weekday& ymwd) noexcept; 508*4d6fc14bSjoergconstexpr year_month_weekday 509*4d6fc14bSjoerg operator-(const year_month_weekday& ymwd, const months& dm) noexcept; 510*4d6fc14bSjoergconstexpr year_month_weekday 511*4d6fc14bSjoerg operator-(const year_month_weekday& ymwd, const years& dy) noexcept; 512*4d6fc14bSjoerg 513*4d6fc14bSjoerg// 25.8.17, class year_month_weekday_last // C++20 514*4d6fc14bSjoergclass year_month_weekday_last; 515*4d6fc14bSjoerg 516*4d6fc14bSjoergconstexpr bool operator==(const year_month_weekday_last& x, 517*4d6fc14bSjoerg const year_month_weekday_last& y) noexcept; 518*4d6fc14bSjoergconstexpr bool operator!=(const year_month_weekday_last& x, 519*4d6fc14bSjoerg const year_month_weekday_last& y) noexcept; 520*4d6fc14bSjoergconstexpr year_month_weekday_last 521*4d6fc14bSjoerg operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept; 522*4d6fc14bSjoergconstexpr year_month_weekday_last 523*4d6fc14bSjoerg operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept; 524*4d6fc14bSjoergconstexpr year_month_weekday_last 525*4d6fc14bSjoerg operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; 526*4d6fc14bSjoergconstexpr year_month_weekday_last 527*4d6fc14bSjoerg operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; 528*4d6fc14bSjoergconstexpr year_month_weekday_last 529*4d6fc14bSjoerg operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; 530*4d6fc14bSjoergconstexpr year_month_weekday_last 531*4d6fc14bSjoerg operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; 532*4d6fc14bSjoerg 533*4d6fc14bSjoerg// 25.8.18, civil calendar conventional syntax operators // C++20 534*4d6fc14bSjoergconstexpr year_month 535*4d6fc14bSjoerg operator/(const year& y, const month& m) noexcept; 536*4d6fc14bSjoergconstexpr year_month 537*4d6fc14bSjoerg operator/(const year& y, int m) noexcept; 538*4d6fc14bSjoergconstexpr month_day 539*4d6fc14bSjoerg operator/(const month& m, const day& d) noexcept; 540*4d6fc14bSjoergconstexpr month_day 541*4d6fc14bSjoerg operator/(const month& m, int d) noexcept; 542*4d6fc14bSjoergconstexpr month_day 543*4d6fc14bSjoerg operator/(int m, const day& d) noexcept; 544*4d6fc14bSjoergconstexpr month_day 545*4d6fc14bSjoerg operator/(const day& d, const month& m) noexcept; 546*4d6fc14bSjoergconstexpr month_day 547*4d6fc14bSjoerg operator/(const day& d, int m) noexcept; 548*4d6fc14bSjoergconstexpr month_day_last 549*4d6fc14bSjoerg operator/(const month& m, last_spec) noexcept; 550*4d6fc14bSjoergconstexpr month_day_last 551*4d6fc14bSjoerg operator/(int m, last_spec) noexcept; 552*4d6fc14bSjoergconstexpr month_day_last 553*4d6fc14bSjoerg operator/(last_spec, const month& m) noexcept; 554*4d6fc14bSjoergconstexpr month_day_last 555*4d6fc14bSjoerg operator/(last_spec, int m) noexcept; 556*4d6fc14bSjoergconstexpr month_weekday 557*4d6fc14bSjoerg operator/(const month& m, const weekday_indexed& wdi) noexcept; 558*4d6fc14bSjoergconstexpr month_weekday 559*4d6fc14bSjoerg operator/(int m, const weekday_indexed& wdi) noexcept; 560*4d6fc14bSjoergconstexpr month_weekday 561*4d6fc14bSjoerg operator/(const weekday_indexed& wdi, const month& m) noexcept; 562*4d6fc14bSjoergconstexpr month_weekday 563*4d6fc14bSjoerg operator/(const weekday_indexed& wdi, int m) noexcept; 564*4d6fc14bSjoergconstexpr month_weekday_last 565*4d6fc14bSjoerg operator/(const month& m, const weekday_last& wdl) noexcept; 566*4d6fc14bSjoergconstexpr month_weekday_last 567*4d6fc14bSjoerg operator/(int m, const weekday_last& wdl) noexcept; 568*4d6fc14bSjoergconstexpr month_weekday_last 569*4d6fc14bSjoerg operator/(const weekday_last& wdl, const month& m) noexcept; 570*4d6fc14bSjoergconstexpr month_weekday_last 571*4d6fc14bSjoerg operator/(const weekday_last& wdl, int m) noexcept; 572*4d6fc14bSjoergconstexpr year_month_day 573*4d6fc14bSjoerg operator/(const year_month& ym, const day& d) noexcept; 574*4d6fc14bSjoergconstexpr year_month_day 575*4d6fc14bSjoerg operator/(const year_month& ym, int d) noexcept; 576*4d6fc14bSjoergconstexpr year_month_day 577*4d6fc14bSjoerg operator/(const year& y, const month_day& md) noexcept; 578*4d6fc14bSjoergconstexpr year_month_day 579*4d6fc14bSjoerg operator/(int y, const month_day& md) noexcept; 580*4d6fc14bSjoergconstexpr year_month_day 581*4d6fc14bSjoerg operator/(const month_day& md, const year& y) noexcept; 582*4d6fc14bSjoergconstexpr year_month_day 583*4d6fc14bSjoerg operator/(const month_day& md, int y) noexcept; 584*4d6fc14bSjoergconstexpr year_month_day_last 585*4d6fc14bSjoerg operator/(const year_month& ym, last_spec) noexcept; 586*4d6fc14bSjoergconstexpr year_month_day_last 587*4d6fc14bSjoerg operator/(const year& y, const month_day_last& mdl) noexcept; 588*4d6fc14bSjoergconstexpr year_month_day_last 589*4d6fc14bSjoerg operator/(int y, const month_day_last& mdl) noexcept; 590*4d6fc14bSjoergconstexpr year_month_day_last 591*4d6fc14bSjoerg operator/(const month_day_last& mdl, const year& y) noexcept; 592*4d6fc14bSjoergconstexpr year_month_day_last 593*4d6fc14bSjoerg operator/(const month_day_last& mdl, int y) noexcept; 594*4d6fc14bSjoergconstexpr year_month_weekday 595*4d6fc14bSjoerg operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; 596*4d6fc14bSjoergconstexpr year_month_weekday 597*4d6fc14bSjoerg operator/(const year& y, const month_weekday& mwd) noexcept; 598*4d6fc14bSjoergconstexpr year_month_weekday 599*4d6fc14bSjoerg operator/(int y, const month_weekday& mwd) noexcept; 600*4d6fc14bSjoergconstexpr year_month_weekday 601*4d6fc14bSjoerg operator/(const month_weekday& mwd, const year& y) noexcept; 602*4d6fc14bSjoergconstexpr year_month_weekday 603*4d6fc14bSjoerg operator/(const month_weekday& mwd, int y) noexcept; 604*4d6fc14bSjoergconstexpr year_month_weekday_last 605*4d6fc14bSjoerg operator/(const year_month& ym, const weekday_last& wdl) noexcept; 606*4d6fc14bSjoergconstexpr year_month_weekday_last 607*4d6fc14bSjoerg operator/(const year& y, const month_weekday_last& mwdl) noexcept; 608*4d6fc14bSjoergconstexpr year_month_weekday_last 609*4d6fc14bSjoerg operator/(int y, const month_weekday_last& mwdl) noexcept; 610*4d6fc14bSjoergconstexpr year_month_weekday_last 611*4d6fc14bSjoerg operator/(const month_weekday_last& mwdl, const year& y) noexcept; 612*4d6fc14bSjoergconstexpr year_month_weekday_last 613*4d6fc14bSjoerg operator/(const month_weekday_last& mwdl, int y) noexcept; 614*4d6fc14bSjoerg 615*4d6fc14bSjoerg// 26.9, class template hh_mm_ss 616*4d6fc14bSjoergtemplate <class Duration> 617*4d6fc14bSjoergclass hh_mm_ss 618*4d6fc14bSjoerg{ 619*4d6fc14bSjoerg bool is_neg; // exposition only 620*4d6fc14bSjoerg chrono::hours h; // exposition only 621*4d6fc14bSjoerg chrono::minutes m; // exposition only 622*4d6fc14bSjoerg chrono::seconds s; // exposition only 623*4d6fc14bSjoerg precision ss; // exposition only 624*4d6fc14bSjoerg 625*4d6fc14bSjoergpublic: 626*4d6fc14bSjoerg static unsigned constexpr fractional_width = see below; 627*4d6fc14bSjoerg using precision = see below; 628*4d6fc14bSjoerg 629*4d6fc14bSjoerg constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {} 630*4d6fc14bSjoerg constexpr explicit hh_mm_ss(Duration d) noexcept; 631*4d6fc14bSjoerg 632*4d6fc14bSjoerg constexpr bool is_negative() const noexcept; 633*4d6fc14bSjoerg constexpr chrono::hours hours() const noexcept; 634*4d6fc14bSjoerg constexpr chrono::minutes minutes() const noexcept; 635*4d6fc14bSjoerg constexpr chrono::seconds seconds() const noexcept; 636*4d6fc14bSjoerg constexpr precision subseconds() const noexcept; 637*4d6fc14bSjoerg 638*4d6fc14bSjoerg constexpr explicit operator precision() const noexcept; 639*4d6fc14bSjoerg constexpr precision to_duration() const noexcept; 640*4d6fc14bSjoerg}; 641*4d6fc14bSjoerg 642*4d6fc14bSjoergtemplate <class charT, class traits, class Duration> 643*4d6fc14bSjoerg basic_ostream<charT, traits>& 644*4d6fc14bSjoerg operator<<(basic_ostream<charT, traits>& os, hh_mm_ss<Duration> const& hms); 645*4d6fc14bSjoerg 646*4d6fc14bSjoerg// 26.10, 12/24 hour functions 647*4d6fc14bSjoergconstexpr bool is_am(hours const& h) noexcept; 648*4d6fc14bSjoergconstexpr bool is_pm(hours const& h) noexcept; 649*4d6fc14bSjoergconstexpr hours make12(const hours& h) noexcept; 650*4d6fc14bSjoergconstexpr hours make24(const hours& h, bool is_pm) noexcept; 651*4d6fc14bSjoerg 652*4d6fc14bSjoerg 653*4d6fc14bSjoerg// 25.10.2, time zone database // C++20 654*4d6fc14bSjoergstruct tzdb; 655*4d6fc14bSjoergclass tzdb_list; 656*4d6fc14bSjoerg 657*4d6fc14bSjoerg// 25.10.2.3, time zone database access // C++20 658*4d6fc14bSjoergconst tzdb& get_tzdb(); 659*4d6fc14bSjoergtzdb_list& get_tzdb_list(); 660*4d6fc14bSjoergconst time_zone* locate_zone(string_view tz_name); 661*4d6fc14bSjoergconst time_zone* current_zone(); 662*4d6fc14bSjoerg 663*4d6fc14bSjoerg// 25.10.2.4, remote time zone database support // C++20 664*4d6fc14bSjoergconst tzdb& reload_tzdb(); 665*4d6fc14bSjoergstring remote_version(); 666*4d6fc14bSjoerg 667*4d6fc14bSjoerg// 25.10.3, exception classes // C++20 668*4d6fc14bSjoergclass nonexistent_local_time; 669*4d6fc14bSjoergclass ambiguous_local_time; 670*4d6fc14bSjoerg 671*4d6fc14bSjoerg// 25.10.4, information classes // C++20 672*4d6fc14bSjoergstruct sys_info; 673*4d6fc14bSjoergstruct local_info; 674*4d6fc14bSjoerg 675*4d6fc14bSjoerg// 25.10.5, class time_zone // C++20 676*4d6fc14bSjoergenum class choose {earliest, latest}; 677*4d6fc14bSjoergclass time_zone; 678*4d6fc14bSjoergbool operator==(const time_zone& x, const time_zone& y) noexcept; 679*4d6fc14bSjoergbool operator!=(const time_zone& x, const time_zone& y) noexcept; 680*4d6fc14bSjoergbool operator<(const time_zone& x, const time_zone& y) noexcept; 681*4d6fc14bSjoergbool operator>(const time_zone& x, const time_zone& y) noexcept; 682*4d6fc14bSjoergbool operator<=(const time_zone& x, const time_zone& y) noexcept; 683*4d6fc14bSjoergbool operator>=(const time_zone& x, const time_zone& y) noexcept; 684*4d6fc14bSjoerg 685*4d6fc14bSjoerg// 25.10.6, class template zoned_traits // C++20 686*4d6fc14bSjoergtemplate<class T> struct zoned_traits; 687*4d6fc14bSjoerg 688*4d6fc14bSjoerg// 25.10.7, class template zoned_time // C++20 689*4d6fc14bSjoergtemplate<class Duration, class TimeZonePtr = const time_zone*> class zoned_time; 690*4d6fc14bSjoergusing zoned_seconds = zoned_time<seconds>; 691*4d6fc14bSjoerg 692*4d6fc14bSjoergtemplate<class Duration1, class Duration2, class TimeZonePtr> 693*4d6fc14bSjoerg bool operator==(const zoned_time<Duration1, TimeZonePtr>& x, 694*4d6fc14bSjoerg const zoned_time<Duration2, TimeZonePtr>& y); 695*4d6fc14bSjoergtemplate<class Duration1, class Duration2, class TimeZonePtr> 696*4d6fc14bSjoerg bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x, 697*4d6fc14bSjoerg const zoned_time<Duration2, TimeZonePtr>& y); 698*4d6fc14bSjoerg 699*4d6fc14bSjoerg// 25.10.8, leap second support // C++20 700*4d6fc14bSjoergclass leap; 701*4d6fc14bSjoerg 702*4d6fc14bSjoergbool operator==(const leap& x, const leap& y); 703*4d6fc14bSjoergbool operator!=(const leap& x, const leap& y); 704*4d6fc14bSjoergbool operator< (const leap& x, const leap& y); 705*4d6fc14bSjoergbool operator> (const leap& x, const leap& y); 706*4d6fc14bSjoergbool operator<=(const leap& x, const leap& y); 707*4d6fc14bSjoergbool operator>=(const leap& x, const leap& y); 708*4d6fc14bSjoergtemplate<class Duration> 709*4d6fc14bSjoerg bool operator==(const leap& x, const sys_time<Duration>& y); 710*4d6fc14bSjoergtemplate<class Duration> 711*4d6fc14bSjoerg bool operator==(const sys_time<Duration>& x, const leap& y); 712*4d6fc14bSjoergtemplate<class Duration> 713*4d6fc14bSjoerg bool operator!=(const leap& x, const sys_time<Duration>& y); 714*4d6fc14bSjoergtemplate<class Duration> 715*4d6fc14bSjoerg bool operator!=(const sys_time<Duration>& x, const leap& y); 716*4d6fc14bSjoergtemplate<class Duration> 717*4d6fc14bSjoerg bool operator< (const leap& x, const sys_time<Duration>& y); 718*4d6fc14bSjoergtemplate<class Duration> 719*4d6fc14bSjoerg bool operator< (const sys_time<Duration>& x, const leap& y); 720*4d6fc14bSjoergtemplate<class Duration> 721*4d6fc14bSjoerg bool operator> (const leap& x, const sys_time<Duration>& y); 722*4d6fc14bSjoergtemplate<class Duration> 723*4d6fc14bSjoerg bool operator> (const sys_time<Duration>& x, const leap& y); 724*4d6fc14bSjoergtemplate<class Duration> 725*4d6fc14bSjoerg bool operator<=(const leap& x, const sys_time<Duration>& y); 726*4d6fc14bSjoergtemplate<class Duration> 727*4d6fc14bSjoerg bool operator<=(const sys_time<Duration>& x, const leap& y); 728*4d6fc14bSjoergtemplate<class Duration> 729*4d6fc14bSjoerg bool operator>=(const leap& x, const sys_time<Duration>& y); 730*4d6fc14bSjoergtemplate<class Duration> 731*4d6fc14bSjoerg bool operator>=(const sys_time<Duration>& x, const leap& y); 732*4d6fc14bSjoerg 733*4d6fc14bSjoerg// 25.10.9, class link // C++20 734*4d6fc14bSjoergclass link; 735*4d6fc14bSjoergbool operator==(const link& x, const link& y); 736*4d6fc14bSjoergbool operator!=(const link& x, const link& y); 737*4d6fc14bSjoergbool operator< (const link& x, const link& y); 738*4d6fc14bSjoergbool operator> (const link& x, const link& y); 739*4d6fc14bSjoergbool operator<=(const link& x, const link& y); 740*4d6fc14bSjoergbool operator>=(const link& x, const link& y); 741*4d6fc14bSjoerg 742*4d6fc14bSjoerg// 25.11, formatting // C++20 743*4d6fc14bSjoergtemplate<class charT, class Streamable> 744*4d6fc14bSjoerg basic_string<charT> 745*4d6fc14bSjoerg format(const charT* fmt, const Streamable& s); 746*4d6fc14bSjoerg 747*4d6fc14bSjoergtemplate<class charT, class Streamable> 748*4d6fc14bSjoerg basic_string<charT> 749*4d6fc14bSjoerg format(const locale& loc, const charT* fmt, const Streamable& s); 750*4d6fc14bSjoerg 751*4d6fc14bSjoergtemplate<class charT, class traits, class Alloc, class Streamable> 752*4d6fc14bSjoerg basic_string<charT, traits, Alloc> 753*4d6fc14bSjoerg format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s); 754*4d6fc14bSjoerg 755*4d6fc14bSjoergtemplate<class charT, class traits, class Alloc, class Streamable> 756*4d6fc14bSjoerg basic_string<charT, traits, Alloc> 757*4d6fc14bSjoerg format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt, 758*4d6fc14bSjoerg const Streamable& s); 759*4d6fc14bSjoerg 760*4d6fc14bSjoerg// 25.12, parsing // C++20 761*4d6fc14bSjoergtemplate<class charT, class traits, class Alloc, class Parsable> 762*4d6fc14bSjoergunspecified 763*4d6fc14bSjoerg parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp); 764*4d6fc14bSjoerg 765*4d6fc14bSjoergtemplate<class charT, class traits, class Alloc, class Parsable> 766*4d6fc14bSjoergunspecified 767*4d6fc14bSjoerg parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, 768*4d6fc14bSjoerg basic_string<charT, traits, Alloc>& abbrev); 769*4d6fc14bSjoerg 770*4d6fc14bSjoergtemplate<class charT, class traits, class Alloc, class Parsable> 771*4d6fc14bSjoergunspecified 772*4d6fc14bSjoerg parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, 773*4d6fc14bSjoerg minutes& offset); 774*4d6fc14bSjoerg 775*4d6fc14bSjoergtemplate<class charT, class traits, class Alloc, class Parsable> 776*4d6fc14bSjoergunspecified 777*4d6fc14bSjoerg parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, 778*4d6fc14bSjoerg basic_string<charT, traits, Alloc>& abbrev, minutes& offset); 779*4d6fc14bSjoerg 780*4d6fc14bSjoerg// calendrical constants 781*4d6fc14bSjoerginline constexpr last_spec last{}; // C++20 782*4d6fc14bSjoerginline constexpr chrono::weekday Sunday{0}; // C++20 783*4d6fc14bSjoerginline constexpr chrono::weekday Monday{1}; // C++20 784*4d6fc14bSjoerginline constexpr chrono::weekday Tuesday{2}; // C++20 785*4d6fc14bSjoerginline constexpr chrono::weekday Wednesday{3}; // C++20 786*4d6fc14bSjoerginline constexpr chrono::weekday Thursday{4}; // C++20 787*4d6fc14bSjoerginline constexpr chrono::weekday Friday{5}; // C++20 788*4d6fc14bSjoerginline constexpr chrono::weekday Saturday{6}; // C++20 789*4d6fc14bSjoerg 790*4d6fc14bSjoerginline constexpr chrono::month January{1}; // C++20 791*4d6fc14bSjoerginline constexpr chrono::month February{2}; // C++20 792*4d6fc14bSjoerginline constexpr chrono::month March{3}; // C++20 793*4d6fc14bSjoerginline constexpr chrono::month April{4}; // C++20 794*4d6fc14bSjoerginline constexpr chrono::month May{5}; // C++20 795*4d6fc14bSjoerginline constexpr chrono::month June{6}; // C++20 796*4d6fc14bSjoerginline constexpr chrono::month July{7}; // C++20 797*4d6fc14bSjoerginline constexpr chrono::month August{8}; // C++20 798*4d6fc14bSjoerginline constexpr chrono::month September{9}; // C++20 799*4d6fc14bSjoerginline constexpr chrono::month October{10}; // C++20 800*4d6fc14bSjoerginline constexpr chrono::month November{11}; // C++20 801*4d6fc14bSjoerginline constexpr chrono::month December{12}; // C++20 802*4d6fc14bSjoerg} // chrono 803*4d6fc14bSjoerg 804*4d6fc14bSjoerginline namespace literals { 805*4d6fc14bSjoerg inline namespace chrono_literals { 806*4d6fc14bSjoergconstexpr chrono::hours operator ""h(unsigned long long); // C++14 807*4d6fc14bSjoergconstexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14 808*4d6fc14bSjoergconstexpr chrono::minutes operator ""min(unsigned long long); // C++14 809*4d6fc14bSjoergconstexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14 810*4d6fc14bSjoergconstexpr chrono::seconds operator ""s(unsigned long long); // C++14 811*4d6fc14bSjoergconstexpr chrono::duration<unspecified > operator ""s(long double); // C++14 812*4d6fc14bSjoergconstexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 813*4d6fc14bSjoergconstexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14 814*4d6fc14bSjoergconstexpr chrono::microseconds operator ""us(unsigned long long); // C++14 815*4d6fc14bSjoergconstexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14 816*4d6fc14bSjoergconstexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 817*4d6fc14bSjoergconstexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14 818*4d6fc14bSjoergconstexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20 819*4d6fc14bSjoergconstexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20 820*4d6fc14bSjoerg} // chrono_literals 821*4d6fc14bSjoerg} // literals 822*4d6fc14bSjoerg 823*4d6fc14bSjoerg} // std 824*4d6fc14bSjoerg*/ 825*4d6fc14bSjoerg 826*4d6fc14bSjoerg#include <__config> 827*4d6fc14bSjoerg#include <__availability> 828*4d6fc14bSjoerg#include <compare> 829*4d6fc14bSjoerg#include <ctime> 830*4d6fc14bSjoerg#include <type_traits> 831*4d6fc14bSjoerg#include <ratio> 832*4d6fc14bSjoerg#include <limits> 833*4d6fc14bSjoerg#include <version> 834*4d6fc14bSjoerg 835*4d6fc14bSjoerg#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 836*4d6fc14bSjoerg#pragma GCC system_header 837*4d6fc14bSjoerg#endif 838*4d6fc14bSjoerg 839*4d6fc14bSjoerg_LIBCPP_PUSH_MACROS 840*4d6fc14bSjoerg#include <__undef_macros> 841*4d6fc14bSjoerg 842*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 843*4d6fc14bSjoerg_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM 844*4d6fc14bSjoergstruct _FilesystemClock; 845*4d6fc14bSjoerg_LIBCPP_END_NAMESPACE_FILESYSTEM 846*4d6fc14bSjoerg#endif // !_LIBCPP_CXX03_LANG 847*4d6fc14bSjoerg 848*4d6fc14bSjoerg_LIBCPP_BEGIN_NAMESPACE_STD 849*4d6fc14bSjoerg 850*4d6fc14bSjoergnamespace chrono 851*4d6fc14bSjoerg{ 852*4d6fc14bSjoerg 853*4d6fc14bSjoergtemplate <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration; 854*4d6fc14bSjoerg 855*4d6fc14bSjoergtemplate <class _Tp> 856*4d6fc14bSjoergstruct __is_duration : false_type {}; 857*4d6fc14bSjoerg 858*4d6fc14bSjoergtemplate <class _Rep, class _Period> 859*4d6fc14bSjoergstruct __is_duration<duration<_Rep, _Period> > : true_type {}; 860*4d6fc14bSjoerg 861*4d6fc14bSjoergtemplate <class _Rep, class _Period> 862*4d6fc14bSjoergstruct __is_duration<const duration<_Rep, _Period> > : true_type {}; 863*4d6fc14bSjoerg 864*4d6fc14bSjoergtemplate <class _Rep, class _Period> 865*4d6fc14bSjoergstruct __is_duration<volatile duration<_Rep, _Period> > : true_type {}; 866*4d6fc14bSjoerg 867*4d6fc14bSjoergtemplate <class _Rep, class _Period> 868*4d6fc14bSjoergstruct __is_duration<const volatile duration<_Rep, _Period> > : true_type {}; 869*4d6fc14bSjoerg 870*4d6fc14bSjoerg} // chrono 871*4d6fc14bSjoerg 872*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 873*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, 874*4d6fc14bSjoerg chrono::duration<_Rep2, _Period2> > 875*4d6fc14bSjoerg{ 876*4d6fc14bSjoerg typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, 877*4d6fc14bSjoerg typename __ratio_gcd<_Period1, _Period2>::type> type; 878*4d6fc14bSjoerg}; 879*4d6fc14bSjoerg 880*4d6fc14bSjoergnamespace chrono { 881*4d6fc14bSjoerg 882*4d6fc14bSjoerg// duration_cast 883*4d6fc14bSjoerg 884*4d6fc14bSjoergtemplate <class _FromDuration, class _ToDuration, 885*4d6fc14bSjoerg class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type, 886*4d6fc14bSjoerg bool = _Period::num == 1, 887*4d6fc14bSjoerg bool = _Period::den == 1> 888*4d6fc14bSjoergstruct __duration_cast; 889*4d6fc14bSjoerg 890*4d6fc14bSjoergtemplate <class _FromDuration, class _ToDuration, class _Period> 891*4d6fc14bSjoergstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> 892*4d6fc14bSjoerg{ 893*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 894*4d6fc14bSjoerg _ToDuration operator()(const _FromDuration& __fd) const 895*4d6fc14bSjoerg { 896*4d6fc14bSjoerg return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count())); 897*4d6fc14bSjoerg } 898*4d6fc14bSjoerg}; 899*4d6fc14bSjoerg 900*4d6fc14bSjoergtemplate <class _FromDuration, class _ToDuration, class _Period> 901*4d6fc14bSjoergstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> 902*4d6fc14bSjoerg{ 903*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 904*4d6fc14bSjoerg _ToDuration operator()(const _FromDuration& __fd) const 905*4d6fc14bSjoerg { 906*4d6fc14bSjoerg typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 907*4d6fc14bSjoerg return _ToDuration(static_cast<typename _ToDuration::rep>( 908*4d6fc14bSjoerg static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); 909*4d6fc14bSjoerg } 910*4d6fc14bSjoerg}; 911*4d6fc14bSjoerg 912*4d6fc14bSjoergtemplate <class _FromDuration, class _ToDuration, class _Period> 913*4d6fc14bSjoergstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> 914*4d6fc14bSjoerg{ 915*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 916*4d6fc14bSjoerg _ToDuration operator()(const _FromDuration& __fd) const 917*4d6fc14bSjoerg { 918*4d6fc14bSjoerg typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 919*4d6fc14bSjoerg return _ToDuration(static_cast<typename _ToDuration::rep>( 920*4d6fc14bSjoerg static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); 921*4d6fc14bSjoerg } 922*4d6fc14bSjoerg}; 923*4d6fc14bSjoerg 924*4d6fc14bSjoergtemplate <class _FromDuration, class _ToDuration, class _Period> 925*4d6fc14bSjoergstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> 926*4d6fc14bSjoerg{ 927*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 928*4d6fc14bSjoerg _ToDuration operator()(const _FromDuration& __fd) const 929*4d6fc14bSjoerg { 930*4d6fc14bSjoerg typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 931*4d6fc14bSjoerg return _ToDuration(static_cast<typename _ToDuration::rep>( 932*4d6fc14bSjoerg static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) 933*4d6fc14bSjoerg / static_cast<_Ct>(_Period::den))); 934*4d6fc14bSjoerg } 935*4d6fc14bSjoerg}; 936*4d6fc14bSjoerg 937*4d6fc14bSjoergtemplate <class _ToDuration, class _Rep, class _Period> 938*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 939*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 940*4d6fc14bSjoergtypename enable_if 941*4d6fc14bSjoerg< 942*4d6fc14bSjoerg __is_duration<_ToDuration>::value, 943*4d6fc14bSjoerg _ToDuration 944*4d6fc14bSjoerg>::type 945*4d6fc14bSjoergduration_cast(const duration<_Rep, _Period>& __fd) 946*4d6fc14bSjoerg{ 947*4d6fc14bSjoerg return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd); 948*4d6fc14bSjoerg} 949*4d6fc14bSjoerg 950*4d6fc14bSjoergtemplate <class _Rep> 951*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {}; 952*4d6fc14bSjoerg 953*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) 954*4d6fc14bSjoergtemplate <class _Rep> 955*4d6fc14bSjoerg_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v 956*4d6fc14bSjoerg = treat_as_floating_point<_Rep>::value; 957*4d6fc14bSjoerg#endif 958*4d6fc14bSjoerg 959*4d6fc14bSjoergtemplate <class _Rep> 960*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS duration_values 961*4d6fc14bSjoerg{ 962*4d6fc14bSjoergpublic: 963*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);} 964*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT {return numeric_limits<_Rep>::max();} 965*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT {return numeric_limits<_Rep>::lowest();} 966*4d6fc14bSjoerg}; 967*4d6fc14bSjoerg 968*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 14 969*4d6fc14bSjoergtemplate <class _ToDuration, class _Rep, class _Period> 970*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 971*4d6fc14bSjoergtypename enable_if 972*4d6fc14bSjoerg< 973*4d6fc14bSjoerg __is_duration<_ToDuration>::value, 974*4d6fc14bSjoerg _ToDuration 975*4d6fc14bSjoerg>::type 976*4d6fc14bSjoergfloor(const duration<_Rep, _Period>& __d) 977*4d6fc14bSjoerg{ 978*4d6fc14bSjoerg _ToDuration __t = duration_cast<_ToDuration>(__d); 979*4d6fc14bSjoerg if (__t > __d) 980*4d6fc14bSjoerg __t = __t - _ToDuration{1}; 981*4d6fc14bSjoerg return __t; 982*4d6fc14bSjoerg} 983*4d6fc14bSjoerg 984*4d6fc14bSjoergtemplate <class _ToDuration, class _Rep, class _Period> 985*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 986*4d6fc14bSjoergtypename enable_if 987*4d6fc14bSjoerg< 988*4d6fc14bSjoerg __is_duration<_ToDuration>::value, 989*4d6fc14bSjoerg _ToDuration 990*4d6fc14bSjoerg>::type 991*4d6fc14bSjoergceil(const duration<_Rep, _Period>& __d) 992*4d6fc14bSjoerg{ 993*4d6fc14bSjoerg _ToDuration __t = duration_cast<_ToDuration>(__d); 994*4d6fc14bSjoerg if (__t < __d) 995*4d6fc14bSjoerg __t = __t + _ToDuration{1}; 996*4d6fc14bSjoerg return __t; 997*4d6fc14bSjoerg} 998*4d6fc14bSjoerg 999*4d6fc14bSjoergtemplate <class _ToDuration, class _Rep, class _Period> 1000*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1001*4d6fc14bSjoergtypename enable_if 1002*4d6fc14bSjoerg< 1003*4d6fc14bSjoerg __is_duration<_ToDuration>::value, 1004*4d6fc14bSjoerg _ToDuration 1005*4d6fc14bSjoerg>::type 1006*4d6fc14bSjoerground(const duration<_Rep, _Period>& __d) 1007*4d6fc14bSjoerg{ 1008*4d6fc14bSjoerg _ToDuration __lower = floor<_ToDuration>(__d); 1009*4d6fc14bSjoerg _ToDuration __upper = __lower + _ToDuration{1}; 1010*4d6fc14bSjoerg auto __lowerDiff = __d - __lower; 1011*4d6fc14bSjoerg auto __upperDiff = __upper - __d; 1012*4d6fc14bSjoerg if (__lowerDiff < __upperDiff) 1013*4d6fc14bSjoerg return __lower; 1014*4d6fc14bSjoerg if (__lowerDiff > __upperDiff) 1015*4d6fc14bSjoerg return __upper; 1016*4d6fc14bSjoerg return __lower.count() & 1 ? __upper : __lower; 1017*4d6fc14bSjoerg} 1018*4d6fc14bSjoerg#endif 1019*4d6fc14bSjoerg 1020*4d6fc14bSjoerg// duration 1021*4d6fc14bSjoerg 1022*4d6fc14bSjoergtemplate <class _Rep, class _Period> 1023*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS duration 1024*4d6fc14bSjoerg{ 1025*4d6fc14bSjoerg static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); 1026*4d6fc14bSjoerg static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); 1027*4d6fc14bSjoerg static_assert(_Period::num > 0, "duration period must be positive"); 1028*4d6fc14bSjoerg 1029*4d6fc14bSjoerg template <class _R1, class _R2> 1030*4d6fc14bSjoerg struct __no_overflow 1031*4d6fc14bSjoerg { 1032*4d6fc14bSjoerg private: 1033*4d6fc14bSjoerg static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; 1034*4d6fc14bSjoerg static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; 1035*4d6fc14bSjoerg static const intmax_t __n1 = _R1::num / __gcd_n1_n2; 1036*4d6fc14bSjoerg static const intmax_t __d1 = _R1::den / __gcd_d1_d2; 1037*4d6fc14bSjoerg static const intmax_t __n2 = _R2::num / __gcd_n1_n2; 1038*4d6fc14bSjoerg static const intmax_t __d2 = _R2::den / __gcd_d1_d2; 1039*4d6fc14bSjoerg static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); 1040*4d6fc14bSjoerg 1041*4d6fc14bSjoerg template <intmax_t _Xp, intmax_t _Yp, bool __overflow> 1042*4d6fc14bSjoerg struct __mul // __overflow == false 1043*4d6fc14bSjoerg { 1044*4d6fc14bSjoerg static const intmax_t value = _Xp * _Yp; 1045*4d6fc14bSjoerg }; 1046*4d6fc14bSjoerg 1047*4d6fc14bSjoerg template <intmax_t _Xp, intmax_t _Yp> 1048*4d6fc14bSjoerg struct __mul<_Xp, _Yp, true> 1049*4d6fc14bSjoerg { 1050*4d6fc14bSjoerg static const intmax_t value = 1; 1051*4d6fc14bSjoerg }; 1052*4d6fc14bSjoerg 1053*4d6fc14bSjoerg public: 1054*4d6fc14bSjoerg static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); 1055*4d6fc14bSjoerg typedef ratio<__mul<__n1, __d2, !value>::value, 1056*4d6fc14bSjoerg __mul<__n2, __d1, !value>::value> type; 1057*4d6fc14bSjoerg }; 1058*4d6fc14bSjoerg 1059*4d6fc14bSjoergpublic: 1060*4d6fc14bSjoerg typedef _Rep rep; 1061*4d6fc14bSjoerg typedef typename _Period::type period; 1062*4d6fc14bSjoergprivate: 1063*4d6fc14bSjoerg rep __rep_; 1064*4d6fc14bSjoergpublic: 1065*4d6fc14bSjoerg 1066*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1067*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 1068*4d6fc14bSjoerg duration() = default; 1069*4d6fc14bSjoerg#else 1070*4d6fc14bSjoerg duration() {} 1071*4d6fc14bSjoerg#endif 1072*4d6fc14bSjoerg 1073*4d6fc14bSjoerg template <class _Rep2> 1074*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1075*4d6fc14bSjoerg explicit duration(const _Rep2& __r, 1076*4d6fc14bSjoerg typename enable_if 1077*4d6fc14bSjoerg < 1078*4d6fc14bSjoerg is_convertible<_Rep2, rep>::value && 1079*4d6fc14bSjoerg (treat_as_floating_point<rep>::value || 1080*4d6fc14bSjoerg !treat_as_floating_point<_Rep2>::value) 1081*4d6fc14bSjoerg >::type* = nullptr) 1082*4d6fc14bSjoerg : __rep_(__r) {} 1083*4d6fc14bSjoerg 1084*4d6fc14bSjoerg // conversions 1085*4d6fc14bSjoerg template <class _Rep2, class _Period2> 1086*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1087*4d6fc14bSjoerg duration(const duration<_Rep2, _Period2>& __d, 1088*4d6fc14bSjoerg typename enable_if 1089*4d6fc14bSjoerg < 1090*4d6fc14bSjoerg __no_overflow<_Period2, period>::value && ( 1091*4d6fc14bSjoerg treat_as_floating_point<rep>::value || 1092*4d6fc14bSjoerg (__no_overflow<_Period2, period>::type::den == 1 && 1093*4d6fc14bSjoerg !treat_as_floating_point<_Rep2>::value)) 1094*4d6fc14bSjoerg >::type* = nullptr) 1095*4d6fc14bSjoerg : __rep_(chrono::duration_cast<duration>(__d).count()) {} 1096*4d6fc14bSjoerg 1097*4d6fc14bSjoerg // observer 1098*4d6fc14bSjoerg 1099*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;} 1100*4d6fc14bSjoerg 1101*4d6fc14bSjoerg // arithmetic 1102*4d6fc14bSjoerg 1103*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);} 1104*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);} 1105*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;} 1106*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);} 1107*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;} 1108*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);} 1109*4d6fc14bSjoerg 1110*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} 1111*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} 1112*4d6fc14bSjoerg 1113*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} 1114*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} 1115*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} 1116*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} 1117*4d6fc14bSjoerg 1118*4d6fc14bSjoerg // special values 1119*4d6fc14bSjoerg 1120*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());} 1121*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {return duration(duration_values<rep>::min());} 1122*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {return duration(duration_values<rep>::max());} 1123*4d6fc14bSjoerg}; 1124*4d6fc14bSjoerg 1125*4d6fc14bSjoergtypedef duration<long long, nano> nanoseconds; 1126*4d6fc14bSjoergtypedef duration<long long, micro> microseconds; 1127*4d6fc14bSjoergtypedef duration<long long, milli> milliseconds; 1128*4d6fc14bSjoergtypedef duration<long long > seconds; 1129*4d6fc14bSjoergtypedef duration< long, ratio< 60> > minutes; 1130*4d6fc14bSjoergtypedef duration< long, ratio<3600> > hours; 1131*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 17 1132*4d6fc14bSjoergtypedef duration< int, ratio_multiply<ratio<24>, hours::period>> days; 1133*4d6fc14bSjoergtypedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks; 1134*4d6fc14bSjoergtypedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years; 1135*4d6fc14bSjoergtypedef duration< int, ratio_divide<years::period, ratio<12>>> months; 1136*4d6fc14bSjoerg#endif 1137*4d6fc14bSjoerg// Duration == 1138*4d6fc14bSjoerg 1139*4d6fc14bSjoergtemplate <class _LhsDuration, class _RhsDuration> 1140*4d6fc14bSjoergstruct __duration_eq 1141*4d6fc14bSjoerg{ 1142*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1143*4d6fc14bSjoerg bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const 1144*4d6fc14bSjoerg { 1145*4d6fc14bSjoerg typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; 1146*4d6fc14bSjoerg return _Ct(__lhs).count() == _Ct(__rhs).count(); 1147*4d6fc14bSjoerg } 1148*4d6fc14bSjoerg}; 1149*4d6fc14bSjoerg 1150*4d6fc14bSjoergtemplate <class _LhsDuration> 1151*4d6fc14bSjoergstruct __duration_eq<_LhsDuration, _LhsDuration> 1152*4d6fc14bSjoerg{ 1153*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1154*4d6fc14bSjoerg bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const 1155*4d6fc14bSjoerg {return __lhs.count() == __rhs.count();} 1156*4d6fc14bSjoerg}; 1157*4d6fc14bSjoerg 1158*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1159*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1160*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1161*4d6fc14bSjoergbool 1162*4d6fc14bSjoergoperator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1163*4d6fc14bSjoerg{ 1164*4d6fc14bSjoerg return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); 1165*4d6fc14bSjoerg} 1166*4d6fc14bSjoerg 1167*4d6fc14bSjoerg// Duration != 1168*4d6fc14bSjoerg 1169*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1170*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1171*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1172*4d6fc14bSjoergbool 1173*4d6fc14bSjoergoperator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1174*4d6fc14bSjoerg{ 1175*4d6fc14bSjoerg return !(__lhs == __rhs); 1176*4d6fc14bSjoerg} 1177*4d6fc14bSjoerg 1178*4d6fc14bSjoerg// Duration < 1179*4d6fc14bSjoerg 1180*4d6fc14bSjoergtemplate <class _LhsDuration, class _RhsDuration> 1181*4d6fc14bSjoergstruct __duration_lt 1182*4d6fc14bSjoerg{ 1183*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1184*4d6fc14bSjoerg bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const 1185*4d6fc14bSjoerg { 1186*4d6fc14bSjoerg typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; 1187*4d6fc14bSjoerg return _Ct(__lhs).count() < _Ct(__rhs).count(); 1188*4d6fc14bSjoerg } 1189*4d6fc14bSjoerg}; 1190*4d6fc14bSjoerg 1191*4d6fc14bSjoergtemplate <class _LhsDuration> 1192*4d6fc14bSjoergstruct __duration_lt<_LhsDuration, _LhsDuration> 1193*4d6fc14bSjoerg{ 1194*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1195*4d6fc14bSjoerg bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const 1196*4d6fc14bSjoerg {return __lhs.count() < __rhs.count();} 1197*4d6fc14bSjoerg}; 1198*4d6fc14bSjoerg 1199*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1200*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1201*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1202*4d6fc14bSjoergbool 1203*4d6fc14bSjoergoperator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1204*4d6fc14bSjoerg{ 1205*4d6fc14bSjoerg return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); 1206*4d6fc14bSjoerg} 1207*4d6fc14bSjoerg 1208*4d6fc14bSjoerg// Duration > 1209*4d6fc14bSjoerg 1210*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1211*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1212*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1213*4d6fc14bSjoergbool 1214*4d6fc14bSjoergoperator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1215*4d6fc14bSjoerg{ 1216*4d6fc14bSjoerg return __rhs < __lhs; 1217*4d6fc14bSjoerg} 1218*4d6fc14bSjoerg 1219*4d6fc14bSjoerg// Duration <= 1220*4d6fc14bSjoerg 1221*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1222*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1223*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1224*4d6fc14bSjoergbool 1225*4d6fc14bSjoergoperator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1226*4d6fc14bSjoerg{ 1227*4d6fc14bSjoerg return !(__rhs < __lhs); 1228*4d6fc14bSjoerg} 1229*4d6fc14bSjoerg 1230*4d6fc14bSjoerg// Duration >= 1231*4d6fc14bSjoerg 1232*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1233*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1234*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1235*4d6fc14bSjoergbool 1236*4d6fc14bSjoergoperator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1237*4d6fc14bSjoerg{ 1238*4d6fc14bSjoerg return !(__lhs < __rhs); 1239*4d6fc14bSjoerg} 1240*4d6fc14bSjoerg 1241*4d6fc14bSjoerg// Duration + 1242*4d6fc14bSjoerg 1243*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1244*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1245*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1246*4d6fc14bSjoergtypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 1247*4d6fc14bSjoergoperator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1248*4d6fc14bSjoerg{ 1249*4d6fc14bSjoerg typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; 1250*4d6fc14bSjoerg return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); 1251*4d6fc14bSjoerg} 1252*4d6fc14bSjoerg 1253*4d6fc14bSjoerg// Duration - 1254*4d6fc14bSjoerg 1255*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1256*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1257*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1258*4d6fc14bSjoergtypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 1259*4d6fc14bSjoergoperator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1260*4d6fc14bSjoerg{ 1261*4d6fc14bSjoerg typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; 1262*4d6fc14bSjoerg return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); 1263*4d6fc14bSjoerg} 1264*4d6fc14bSjoerg 1265*4d6fc14bSjoerg// Duration * 1266*4d6fc14bSjoerg 1267*4d6fc14bSjoergtemplate <class _Rep1, class _Period, class _Rep2> 1268*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1269*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1270*4d6fc14bSjoergtypename enable_if 1271*4d6fc14bSjoerg< 1272*4d6fc14bSjoerg is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, 1273*4d6fc14bSjoerg duration<typename common_type<_Rep1, _Rep2>::type, _Period> 1274*4d6fc14bSjoerg>::type 1275*4d6fc14bSjoergoperator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 1276*4d6fc14bSjoerg{ 1277*4d6fc14bSjoerg typedef typename common_type<_Rep1, _Rep2>::type _Cr; 1278*4d6fc14bSjoerg typedef duration<_Cr, _Period> _Cd; 1279*4d6fc14bSjoerg return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); 1280*4d6fc14bSjoerg} 1281*4d6fc14bSjoerg 1282*4d6fc14bSjoergtemplate <class _Rep1, class _Period, class _Rep2> 1283*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1284*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1285*4d6fc14bSjoergtypename enable_if 1286*4d6fc14bSjoerg< 1287*4d6fc14bSjoerg is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, 1288*4d6fc14bSjoerg duration<typename common_type<_Rep1, _Rep2>::type, _Period> 1289*4d6fc14bSjoerg>::type 1290*4d6fc14bSjoergoperator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) 1291*4d6fc14bSjoerg{ 1292*4d6fc14bSjoerg return __d * __s; 1293*4d6fc14bSjoerg} 1294*4d6fc14bSjoerg 1295*4d6fc14bSjoerg// Duration / 1296*4d6fc14bSjoerg 1297*4d6fc14bSjoergtemplate <class _Rep1, class _Period, class _Rep2> 1298*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1299*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1300*4d6fc14bSjoergtypename enable_if 1301*4d6fc14bSjoerg< 1302*4d6fc14bSjoerg !__is_duration<_Rep2>::value && 1303*4d6fc14bSjoerg is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, 1304*4d6fc14bSjoerg duration<typename common_type<_Rep1, _Rep2>::type, _Period> 1305*4d6fc14bSjoerg>::type 1306*4d6fc14bSjoergoperator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 1307*4d6fc14bSjoerg{ 1308*4d6fc14bSjoerg typedef typename common_type<_Rep1, _Rep2>::type _Cr; 1309*4d6fc14bSjoerg typedef duration<_Cr, _Period> _Cd; 1310*4d6fc14bSjoerg return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); 1311*4d6fc14bSjoerg} 1312*4d6fc14bSjoerg 1313*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1314*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1315*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1316*4d6fc14bSjoergtypename common_type<_Rep1, _Rep2>::type 1317*4d6fc14bSjoergoperator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1318*4d6fc14bSjoerg{ 1319*4d6fc14bSjoerg typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct; 1320*4d6fc14bSjoerg return _Ct(__lhs).count() / _Ct(__rhs).count(); 1321*4d6fc14bSjoerg} 1322*4d6fc14bSjoerg 1323*4d6fc14bSjoerg// Duration % 1324*4d6fc14bSjoerg 1325*4d6fc14bSjoergtemplate <class _Rep1, class _Period, class _Rep2> 1326*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1327*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1328*4d6fc14bSjoergtypename enable_if 1329*4d6fc14bSjoerg< 1330*4d6fc14bSjoerg !__is_duration<_Rep2>::value && 1331*4d6fc14bSjoerg is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, 1332*4d6fc14bSjoerg duration<typename common_type<_Rep1, _Rep2>::type, _Period> 1333*4d6fc14bSjoerg>::type 1334*4d6fc14bSjoergoperator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 1335*4d6fc14bSjoerg{ 1336*4d6fc14bSjoerg typedef typename common_type<_Rep1, _Rep2>::type _Cr; 1337*4d6fc14bSjoerg typedef duration<_Cr, _Period> _Cd; 1338*4d6fc14bSjoerg return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); 1339*4d6fc14bSjoerg} 1340*4d6fc14bSjoerg 1341*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 1342*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY 1343*4d6fc14bSjoerg_LIBCPP_CONSTEXPR 1344*4d6fc14bSjoergtypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 1345*4d6fc14bSjoergoperator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1346*4d6fc14bSjoerg{ 1347*4d6fc14bSjoerg typedef typename common_type<_Rep1, _Rep2>::type _Cr; 1348*4d6fc14bSjoerg typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; 1349*4d6fc14bSjoerg return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); 1350*4d6fc14bSjoerg} 1351*4d6fc14bSjoerg 1352*4d6fc14bSjoerg////////////////////////////////////////////////////////// 1353*4d6fc14bSjoerg///////////////////// time_point ///////////////////////// 1354*4d6fc14bSjoerg////////////////////////////////////////////////////////// 1355*4d6fc14bSjoerg 1356*4d6fc14bSjoergtemplate <class _Clock, class _Duration = typename _Clock::duration> 1357*4d6fc14bSjoergclass _LIBCPP_TEMPLATE_VIS time_point 1358*4d6fc14bSjoerg{ 1359*4d6fc14bSjoerg static_assert(__is_duration<_Duration>::value, 1360*4d6fc14bSjoerg "Second template parameter of time_point must be a std::chrono::duration"); 1361*4d6fc14bSjoergpublic: 1362*4d6fc14bSjoerg typedef _Clock clock; 1363*4d6fc14bSjoerg typedef _Duration duration; 1364*4d6fc14bSjoerg typedef typename duration::rep rep; 1365*4d6fc14bSjoerg typedef typename duration::period period; 1366*4d6fc14bSjoergprivate: 1367*4d6fc14bSjoerg duration __d_; 1368*4d6fc14bSjoerg 1369*4d6fc14bSjoergpublic: 1370*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {} 1371*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {} 1372*4d6fc14bSjoerg 1373*4d6fc14bSjoerg // conversions 1374*4d6fc14bSjoerg template <class _Duration2> 1375*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1376*4d6fc14bSjoerg time_point(const time_point<clock, _Duration2>& t, 1377*4d6fc14bSjoerg typename enable_if 1378*4d6fc14bSjoerg < 1379*4d6fc14bSjoerg is_convertible<_Duration2, duration>::value 1380*4d6fc14bSjoerg >::type* = nullptr) 1381*4d6fc14bSjoerg : __d_(t.time_since_epoch()) {} 1382*4d6fc14bSjoerg 1383*4d6fc14bSjoerg // observer 1384*4d6fc14bSjoerg 1385*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;} 1386*4d6fc14bSjoerg 1387*4d6fc14bSjoerg // arithmetic 1388*4d6fc14bSjoerg 1389*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} 1390*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} 1391*4d6fc14bSjoerg 1392*4d6fc14bSjoerg // special values 1393*4d6fc14bSjoerg 1394*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());} 1395*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());} 1396*4d6fc14bSjoerg}; 1397*4d6fc14bSjoerg 1398*4d6fc14bSjoerg} // chrono 1399*4d6fc14bSjoerg 1400*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Duration2> 1401*4d6fc14bSjoergstruct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>, 1402*4d6fc14bSjoerg chrono::time_point<_Clock, _Duration2> > 1403*4d6fc14bSjoerg{ 1404*4d6fc14bSjoerg typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; 1405*4d6fc14bSjoerg}; 1406*4d6fc14bSjoerg 1407*4d6fc14bSjoergnamespace chrono { 1408*4d6fc14bSjoerg 1409*4d6fc14bSjoergtemplate <class _ToDuration, class _Clock, class _Duration> 1410*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1411*4d6fc14bSjoergtime_point<_Clock, _ToDuration> 1412*4d6fc14bSjoergtime_point_cast(const time_point<_Clock, _Duration>& __t) 1413*4d6fc14bSjoerg{ 1414*4d6fc14bSjoerg return time_point<_Clock, _ToDuration>(chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); 1415*4d6fc14bSjoerg} 1416*4d6fc14bSjoerg 1417*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 14 1418*4d6fc14bSjoergtemplate <class _ToDuration, class _Clock, class _Duration> 1419*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1420*4d6fc14bSjoergtypename enable_if 1421*4d6fc14bSjoerg< 1422*4d6fc14bSjoerg __is_duration<_ToDuration>::value, 1423*4d6fc14bSjoerg time_point<_Clock, _ToDuration> 1424*4d6fc14bSjoerg>::type 1425*4d6fc14bSjoergfloor(const time_point<_Clock, _Duration>& __t) 1426*4d6fc14bSjoerg{ 1427*4d6fc14bSjoerg return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; 1428*4d6fc14bSjoerg} 1429*4d6fc14bSjoerg 1430*4d6fc14bSjoergtemplate <class _ToDuration, class _Clock, class _Duration> 1431*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1432*4d6fc14bSjoergtypename enable_if 1433*4d6fc14bSjoerg< 1434*4d6fc14bSjoerg __is_duration<_ToDuration>::value, 1435*4d6fc14bSjoerg time_point<_Clock, _ToDuration> 1436*4d6fc14bSjoerg>::type 1437*4d6fc14bSjoergceil(const time_point<_Clock, _Duration>& __t) 1438*4d6fc14bSjoerg{ 1439*4d6fc14bSjoerg return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; 1440*4d6fc14bSjoerg} 1441*4d6fc14bSjoerg 1442*4d6fc14bSjoergtemplate <class _ToDuration, class _Clock, class _Duration> 1443*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1444*4d6fc14bSjoergtypename enable_if 1445*4d6fc14bSjoerg< 1446*4d6fc14bSjoerg __is_duration<_ToDuration>::value, 1447*4d6fc14bSjoerg time_point<_Clock, _ToDuration> 1448*4d6fc14bSjoerg>::type 1449*4d6fc14bSjoerground(const time_point<_Clock, _Duration>& __t) 1450*4d6fc14bSjoerg{ 1451*4d6fc14bSjoerg return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; 1452*4d6fc14bSjoerg} 1453*4d6fc14bSjoerg 1454*4d6fc14bSjoergtemplate <class _Rep, class _Period> 1455*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1456*4d6fc14bSjoergtypename enable_if 1457*4d6fc14bSjoerg< 1458*4d6fc14bSjoerg numeric_limits<_Rep>::is_signed, 1459*4d6fc14bSjoerg duration<_Rep, _Period> 1460*4d6fc14bSjoerg>::type 1461*4d6fc14bSjoergabs(duration<_Rep, _Period> __d) 1462*4d6fc14bSjoerg{ 1463*4d6fc14bSjoerg return __d >= __d.zero() ? +__d : -__d; 1464*4d6fc14bSjoerg} 1465*4d6fc14bSjoerg#endif 1466*4d6fc14bSjoerg 1467*4d6fc14bSjoerg// time_point == 1468*4d6fc14bSjoerg 1469*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Duration2> 1470*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1471*4d6fc14bSjoergbool 1472*4d6fc14bSjoergoperator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 1473*4d6fc14bSjoerg{ 1474*4d6fc14bSjoerg return __lhs.time_since_epoch() == __rhs.time_since_epoch(); 1475*4d6fc14bSjoerg} 1476*4d6fc14bSjoerg 1477*4d6fc14bSjoerg// time_point != 1478*4d6fc14bSjoerg 1479*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Duration2> 1480*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1481*4d6fc14bSjoergbool 1482*4d6fc14bSjoergoperator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 1483*4d6fc14bSjoerg{ 1484*4d6fc14bSjoerg return !(__lhs == __rhs); 1485*4d6fc14bSjoerg} 1486*4d6fc14bSjoerg 1487*4d6fc14bSjoerg// time_point < 1488*4d6fc14bSjoerg 1489*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Duration2> 1490*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1491*4d6fc14bSjoergbool 1492*4d6fc14bSjoergoperator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 1493*4d6fc14bSjoerg{ 1494*4d6fc14bSjoerg return __lhs.time_since_epoch() < __rhs.time_since_epoch(); 1495*4d6fc14bSjoerg} 1496*4d6fc14bSjoerg 1497*4d6fc14bSjoerg// time_point > 1498*4d6fc14bSjoerg 1499*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Duration2> 1500*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1501*4d6fc14bSjoergbool 1502*4d6fc14bSjoergoperator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 1503*4d6fc14bSjoerg{ 1504*4d6fc14bSjoerg return __rhs < __lhs; 1505*4d6fc14bSjoerg} 1506*4d6fc14bSjoerg 1507*4d6fc14bSjoerg// time_point <= 1508*4d6fc14bSjoerg 1509*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Duration2> 1510*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1511*4d6fc14bSjoergbool 1512*4d6fc14bSjoergoperator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 1513*4d6fc14bSjoerg{ 1514*4d6fc14bSjoerg return !(__rhs < __lhs); 1515*4d6fc14bSjoerg} 1516*4d6fc14bSjoerg 1517*4d6fc14bSjoerg// time_point >= 1518*4d6fc14bSjoerg 1519*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Duration2> 1520*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1521*4d6fc14bSjoergbool 1522*4d6fc14bSjoergoperator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 1523*4d6fc14bSjoerg{ 1524*4d6fc14bSjoerg return !(__lhs < __rhs); 1525*4d6fc14bSjoerg} 1526*4d6fc14bSjoerg 1527*4d6fc14bSjoerg// time_point operator+(time_point x, duration y); 1528*4d6fc14bSjoerg 1529*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Rep2, class _Period2> 1530*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1531*4d6fc14bSjoergtime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> 1532*4d6fc14bSjoergoperator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1533*4d6fc14bSjoerg{ 1534*4d6fc14bSjoerg typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; 1535*4d6fc14bSjoerg return _Tr (__lhs.time_since_epoch() + __rhs); 1536*4d6fc14bSjoerg} 1537*4d6fc14bSjoerg 1538*4d6fc14bSjoerg// time_point operator+(duration x, time_point y); 1539*4d6fc14bSjoerg 1540*4d6fc14bSjoergtemplate <class _Rep1, class _Period1, class _Clock, class _Duration2> 1541*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1542*4d6fc14bSjoergtime_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> 1543*4d6fc14bSjoergoperator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 1544*4d6fc14bSjoerg{ 1545*4d6fc14bSjoerg return __rhs + __lhs; 1546*4d6fc14bSjoerg} 1547*4d6fc14bSjoerg 1548*4d6fc14bSjoerg// time_point operator-(time_point x, duration y); 1549*4d6fc14bSjoerg 1550*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Rep2, class _Period2> 1551*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1552*4d6fc14bSjoergtime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> 1553*4d6fc14bSjoergoperator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 1554*4d6fc14bSjoerg{ 1555*4d6fc14bSjoerg typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; 1556*4d6fc14bSjoerg return _Ret(__lhs.time_since_epoch() -__rhs); 1557*4d6fc14bSjoerg} 1558*4d6fc14bSjoerg 1559*4d6fc14bSjoerg// duration operator-(time_point x, time_point y); 1560*4d6fc14bSjoerg 1561*4d6fc14bSjoergtemplate <class _Clock, class _Duration1, class _Duration2> 1562*4d6fc14bSjoerginline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 1563*4d6fc14bSjoergtypename common_type<_Duration1, _Duration2>::type 1564*4d6fc14bSjoergoperator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 1565*4d6fc14bSjoerg{ 1566*4d6fc14bSjoerg return __lhs.time_since_epoch() - __rhs.time_since_epoch(); 1567*4d6fc14bSjoerg} 1568*4d6fc14bSjoerg 1569*4d6fc14bSjoerg////////////////////////////////////////////////////////// 1570*4d6fc14bSjoerg/////////////////////// clocks /////////////////////////// 1571*4d6fc14bSjoerg////////////////////////////////////////////////////////// 1572*4d6fc14bSjoerg 1573*4d6fc14bSjoergclass _LIBCPP_TYPE_VIS system_clock 1574*4d6fc14bSjoerg{ 1575*4d6fc14bSjoergpublic: 1576*4d6fc14bSjoerg typedef microseconds duration; 1577*4d6fc14bSjoerg typedef duration::rep rep; 1578*4d6fc14bSjoerg typedef duration::period period; 1579*4d6fc14bSjoerg typedef chrono::time_point<system_clock> time_point; 1580*4d6fc14bSjoerg static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; 1581*4d6fc14bSjoerg 1582*4d6fc14bSjoerg static time_point now() _NOEXCEPT; 1583*4d6fc14bSjoerg static time_t to_time_t (const time_point& __t) _NOEXCEPT; 1584*4d6fc14bSjoerg static time_point from_time_t(time_t __t) _NOEXCEPT; 1585*4d6fc14bSjoerg}; 1586*4d6fc14bSjoerg 1587*4d6fc14bSjoerg#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK 1588*4d6fc14bSjoergclass _LIBCPP_TYPE_VIS steady_clock 1589*4d6fc14bSjoerg{ 1590*4d6fc14bSjoergpublic: 1591*4d6fc14bSjoerg typedef nanoseconds duration; 1592*4d6fc14bSjoerg typedef duration::rep rep; 1593*4d6fc14bSjoerg typedef duration::period period; 1594*4d6fc14bSjoerg typedef chrono::time_point<steady_clock, duration> time_point; 1595*4d6fc14bSjoerg static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true; 1596*4d6fc14bSjoerg 1597*4d6fc14bSjoerg static time_point now() _NOEXCEPT; 1598*4d6fc14bSjoerg}; 1599*4d6fc14bSjoerg 1600*4d6fc14bSjoergtypedef steady_clock high_resolution_clock; 1601*4d6fc14bSjoerg#else 1602*4d6fc14bSjoergtypedef system_clock high_resolution_clock; 1603*4d6fc14bSjoerg#endif 1604*4d6fc14bSjoerg 1605*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 17 1606*4d6fc14bSjoerg// [time.clock.file], type file_clock 1607*4d6fc14bSjoergusing file_clock = _VSTD_FS::_FilesystemClock; 1608*4d6fc14bSjoerg 1609*4d6fc14bSjoergtemplate<class _Duration> 1610*4d6fc14bSjoergusing file_time = time_point<file_clock, _Duration>; 1611*4d6fc14bSjoerg 1612*4d6fc14bSjoerg 1613*4d6fc14bSjoergtemplate <class _Duration> 1614*4d6fc14bSjoergusing sys_time = time_point<system_clock, _Duration>; 1615*4d6fc14bSjoergusing sys_seconds = sys_time<seconds>; 1616*4d6fc14bSjoergusing sys_days = sys_time<days>; 1617*4d6fc14bSjoerg 1618*4d6fc14bSjoergstruct local_t {}; 1619*4d6fc14bSjoergtemplate<class Duration> 1620*4d6fc14bSjoergusing local_time = time_point<local_t, Duration>; 1621*4d6fc14bSjoergusing local_seconds = local_time<seconds>; 1622*4d6fc14bSjoergusing local_days = local_time<days>; 1623*4d6fc14bSjoerg 1624*4d6fc14bSjoerg 1625*4d6fc14bSjoergstruct last_spec { explicit last_spec() = default; }; 1626*4d6fc14bSjoerg 1627*4d6fc14bSjoergclass day { 1628*4d6fc14bSjoergprivate: 1629*4d6fc14bSjoerg unsigned char __d; 1630*4d6fc14bSjoergpublic: 1631*4d6fc14bSjoerg day() = default; 1632*4d6fc14bSjoerg explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {} 1633*4d6fc14bSjoerg inline constexpr day& operator++() noexcept { ++__d; return *this; } 1634*4d6fc14bSjoerg inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } 1635*4d6fc14bSjoerg inline constexpr day& operator--() noexcept { --__d; return *this; } 1636*4d6fc14bSjoerg inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } 1637*4d6fc14bSjoerg constexpr day& operator+=(const days& __dd) noexcept; 1638*4d6fc14bSjoerg constexpr day& operator-=(const days& __dd) noexcept; 1639*4d6fc14bSjoerg explicit inline constexpr operator unsigned() const noexcept { return __d; } 1640*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; } 1641*4d6fc14bSjoerg }; 1642*4d6fc14bSjoerg 1643*4d6fc14bSjoerg 1644*4d6fc14bSjoerginline constexpr 1645*4d6fc14bSjoergbool operator==(const day& __lhs, const day& __rhs) noexcept 1646*4d6fc14bSjoerg{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } 1647*4d6fc14bSjoerg 1648*4d6fc14bSjoerginline constexpr 1649*4d6fc14bSjoergbool operator!=(const day& __lhs, const day& __rhs) noexcept 1650*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 1651*4d6fc14bSjoerg 1652*4d6fc14bSjoerginline constexpr 1653*4d6fc14bSjoergbool operator< (const day& __lhs, const day& __rhs) noexcept 1654*4d6fc14bSjoerg{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } 1655*4d6fc14bSjoerg 1656*4d6fc14bSjoerginline constexpr 1657*4d6fc14bSjoergbool operator> (const day& __lhs, const day& __rhs) noexcept 1658*4d6fc14bSjoerg{ return __rhs < __lhs; } 1659*4d6fc14bSjoerg 1660*4d6fc14bSjoerginline constexpr 1661*4d6fc14bSjoergbool operator<=(const day& __lhs, const day& __rhs) noexcept 1662*4d6fc14bSjoerg{ return !(__rhs < __lhs);} 1663*4d6fc14bSjoerg 1664*4d6fc14bSjoerginline constexpr 1665*4d6fc14bSjoergbool operator>=(const day& __lhs, const day& __rhs) noexcept 1666*4d6fc14bSjoerg{ return !(__lhs < __rhs); } 1667*4d6fc14bSjoerg 1668*4d6fc14bSjoerginline constexpr 1669*4d6fc14bSjoergday operator+ (const day& __lhs, const days& __rhs) noexcept 1670*4d6fc14bSjoerg{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); } 1671*4d6fc14bSjoerg 1672*4d6fc14bSjoerginline constexpr 1673*4d6fc14bSjoergday operator+ (const days& __lhs, const day& __rhs) noexcept 1674*4d6fc14bSjoerg{ return __rhs + __lhs; } 1675*4d6fc14bSjoerg 1676*4d6fc14bSjoerginline constexpr 1677*4d6fc14bSjoergday operator- (const day& __lhs, const days& __rhs) noexcept 1678*4d6fc14bSjoerg{ return __lhs + -__rhs; } 1679*4d6fc14bSjoerg 1680*4d6fc14bSjoerginline constexpr 1681*4d6fc14bSjoergdays operator-(const day& __lhs, const day& __rhs) noexcept 1682*4d6fc14bSjoerg{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) - 1683*4d6fc14bSjoerg static_cast<int>(static_cast<unsigned>(__rhs))); } 1684*4d6fc14bSjoerg 1685*4d6fc14bSjoerginline constexpr day& day::operator+=(const days& __dd) noexcept 1686*4d6fc14bSjoerg{ *this = *this + __dd; return *this; } 1687*4d6fc14bSjoerg 1688*4d6fc14bSjoerginline constexpr day& day::operator-=(const days& __dd) noexcept 1689*4d6fc14bSjoerg{ *this = *this - __dd; return *this; } 1690*4d6fc14bSjoerg 1691*4d6fc14bSjoerg 1692*4d6fc14bSjoergclass month { 1693*4d6fc14bSjoergprivate: 1694*4d6fc14bSjoerg unsigned char __m; 1695*4d6fc14bSjoergpublic: 1696*4d6fc14bSjoerg month() = default; 1697*4d6fc14bSjoerg explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {} 1698*4d6fc14bSjoerg inline constexpr month& operator++() noexcept { ++__m; return *this; } 1699*4d6fc14bSjoerg inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; } 1700*4d6fc14bSjoerg inline constexpr month& operator--() noexcept { --__m; return *this; } 1701*4d6fc14bSjoerg inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; } 1702*4d6fc14bSjoerg constexpr month& operator+=(const months& __m1) noexcept; 1703*4d6fc14bSjoerg constexpr month& operator-=(const months& __m1) noexcept; 1704*4d6fc14bSjoerg explicit inline constexpr operator unsigned() const noexcept { return __m; } 1705*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; } 1706*4d6fc14bSjoerg}; 1707*4d6fc14bSjoerg 1708*4d6fc14bSjoerg 1709*4d6fc14bSjoerginline constexpr 1710*4d6fc14bSjoergbool operator==(const month& __lhs, const month& __rhs) noexcept 1711*4d6fc14bSjoerg{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } 1712*4d6fc14bSjoerg 1713*4d6fc14bSjoerginline constexpr 1714*4d6fc14bSjoergbool operator!=(const month& __lhs, const month& __rhs) noexcept 1715*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 1716*4d6fc14bSjoerg 1717*4d6fc14bSjoerginline constexpr 1718*4d6fc14bSjoergbool operator< (const month& __lhs, const month& __rhs) noexcept 1719*4d6fc14bSjoerg{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } 1720*4d6fc14bSjoerg 1721*4d6fc14bSjoerginline constexpr 1722*4d6fc14bSjoergbool operator> (const month& __lhs, const month& __rhs) noexcept 1723*4d6fc14bSjoerg{ return __rhs < __lhs; } 1724*4d6fc14bSjoerg 1725*4d6fc14bSjoerginline constexpr 1726*4d6fc14bSjoergbool operator<=(const month& __lhs, const month& __rhs) noexcept 1727*4d6fc14bSjoerg{ return !(__rhs < __lhs); } 1728*4d6fc14bSjoerg 1729*4d6fc14bSjoerginline constexpr 1730*4d6fc14bSjoergbool operator>=(const month& __lhs, const month& __rhs) noexcept 1731*4d6fc14bSjoerg{ return !(__lhs < __rhs); } 1732*4d6fc14bSjoerg 1733*4d6fc14bSjoerginline constexpr 1734*4d6fc14bSjoergmonth operator+ (const month& __lhs, const months& __rhs) noexcept 1735*4d6fc14bSjoerg{ 1736*4d6fc14bSjoerg auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1); 1737*4d6fc14bSjoerg auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; 1738*4d6fc14bSjoerg return month{static_cast<unsigned>(__mu - __yr * 12 + 1)}; 1739*4d6fc14bSjoerg} 1740*4d6fc14bSjoerg 1741*4d6fc14bSjoerginline constexpr 1742*4d6fc14bSjoergmonth operator+ (const months& __lhs, const month& __rhs) noexcept 1743*4d6fc14bSjoerg{ return __rhs + __lhs; } 1744*4d6fc14bSjoerg 1745*4d6fc14bSjoerginline constexpr 1746*4d6fc14bSjoergmonth operator- (const month& __lhs, const months& __rhs) noexcept 1747*4d6fc14bSjoerg{ return __lhs + -__rhs; } 1748*4d6fc14bSjoerg 1749*4d6fc14bSjoerginline constexpr 1750*4d6fc14bSjoergmonths operator-(const month& __lhs, const month& __rhs) noexcept 1751*4d6fc14bSjoerg{ 1752*4d6fc14bSjoerg auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs); 1753*4d6fc14bSjoerg return months(__dm <= 11 ? __dm : __dm + 12); 1754*4d6fc14bSjoerg} 1755*4d6fc14bSjoerg 1756*4d6fc14bSjoerginline constexpr month& month::operator+=(const months& __dm) noexcept 1757*4d6fc14bSjoerg{ *this = *this + __dm; return *this; } 1758*4d6fc14bSjoerg 1759*4d6fc14bSjoerginline constexpr month& month::operator-=(const months& __dm) noexcept 1760*4d6fc14bSjoerg{ *this = *this - __dm; return *this; } 1761*4d6fc14bSjoerg 1762*4d6fc14bSjoerg 1763*4d6fc14bSjoergclass year { 1764*4d6fc14bSjoergprivate: 1765*4d6fc14bSjoerg short __y; 1766*4d6fc14bSjoergpublic: 1767*4d6fc14bSjoerg year() = default; 1768*4d6fc14bSjoerg explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {} 1769*4d6fc14bSjoerg 1770*4d6fc14bSjoerg inline constexpr year& operator++() noexcept { ++__y; return *this; } 1771*4d6fc14bSjoerg inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; } 1772*4d6fc14bSjoerg inline constexpr year& operator--() noexcept { --__y; return *this; } 1773*4d6fc14bSjoerg inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; } 1774*4d6fc14bSjoerg constexpr year& operator+=(const years& __dy) noexcept; 1775*4d6fc14bSjoerg constexpr year& operator-=(const years& __dy) noexcept; 1776*4d6fc14bSjoerg inline constexpr year operator+() const noexcept { return *this; } 1777*4d6fc14bSjoerg inline constexpr year operator-() const noexcept { return year{-__y}; } 1778*4d6fc14bSjoerg 1779*4d6fc14bSjoerg inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); } 1780*4d6fc14bSjoerg explicit inline constexpr operator int() const noexcept { return __y; } 1781*4d6fc14bSjoerg constexpr bool ok() const noexcept; 1782*4d6fc14bSjoerg static inline constexpr year min() noexcept { return year{-32767}; } 1783*4d6fc14bSjoerg static inline constexpr year max() noexcept { return year{ 32767}; } 1784*4d6fc14bSjoerg}; 1785*4d6fc14bSjoerg 1786*4d6fc14bSjoerg 1787*4d6fc14bSjoerginline constexpr 1788*4d6fc14bSjoergbool operator==(const year& __lhs, const year& __rhs) noexcept 1789*4d6fc14bSjoerg{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); } 1790*4d6fc14bSjoerg 1791*4d6fc14bSjoerginline constexpr 1792*4d6fc14bSjoergbool operator!=(const year& __lhs, const year& __rhs) noexcept 1793*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 1794*4d6fc14bSjoerg 1795*4d6fc14bSjoerginline constexpr 1796*4d6fc14bSjoergbool operator< (const year& __lhs, const year& __rhs) noexcept 1797*4d6fc14bSjoerg{ return static_cast<int>(__lhs) < static_cast<int>(__rhs); } 1798*4d6fc14bSjoerg 1799*4d6fc14bSjoerginline constexpr 1800*4d6fc14bSjoergbool operator> (const year& __lhs, const year& __rhs) noexcept 1801*4d6fc14bSjoerg{ return __rhs < __lhs; } 1802*4d6fc14bSjoerg 1803*4d6fc14bSjoerginline constexpr 1804*4d6fc14bSjoergbool operator<=(const year& __lhs, const year& __rhs) noexcept 1805*4d6fc14bSjoerg{ return !(__rhs < __lhs); } 1806*4d6fc14bSjoerg 1807*4d6fc14bSjoerginline constexpr 1808*4d6fc14bSjoergbool operator>=(const year& __lhs, const year& __rhs) noexcept 1809*4d6fc14bSjoerg{ return !(__lhs < __rhs); } 1810*4d6fc14bSjoerg 1811*4d6fc14bSjoerginline constexpr 1812*4d6fc14bSjoergyear operator+ (const year& __lhs, const years& __rhs) noexcept 1813*4d6fc14bSjoerg{ return year(static_cast<int>(__lhs) + __rhs.count()); } 1814*4d6fc14bSjoerg 1815*4d6fc14bSjoerginline constexpr 1816*4d6fc14bSjoergyear operator+ (const years& __lhs, const year& __rhs) noexcept 1817*4d6fc14bSjoerg{ return __rhs + __lhs; } 1818*4d6fc14bSjoerg 1819*4d6fc14bSjoerginline constexpr 1820*4d6fc14bSjoergyear operator- (const year& __lhs, const years& __rhs) noexcept 1821*4d6fc14bSjoerg{ return __lhs + -__rhs; } 1822*4d6fc14bSjoerg 1823*4d6fc14bSjoerginline constexpr 1824*4d6fc14bSjoergyears operator-(const year& __lhs, const year& __rhs) noexcept 1825*4d6fc14bSjoerg{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; } 1826*4d6fc14bSjoerg 1827*4d6fc14bSjoerg 1828*4d6fc14bSjoerginline constexpr year& year::operator+=(const years& __dy) noexcept 1829*4d6fc14bSjoerg{ *this = *this + __dy; return *this; } 1830*4d6fc14bSjoerg 1831*4d6fc14bSjoerginline constexpr year& year::operator-=(const years& __dy) noexcept 1832*4d6fc14bSjoerg{ *this = *this - __dy; return *this; } 1833*4d6fc14bSjoerg 1834*4d6fc14bSjoerginline constexpr bool year::ok() const noexcept 1835*4d6fc14bSjoerg{ return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); } 1836*4d6fc14bSjoerg 1837*4d6fc14bSjoergclass weekday_indexed; 1838*4d6fc14bSjoergclass weekday_last; 1839*4d6fc14bSjoerg 1840*4d6fc14bSjoergclass weekday { 1841*4d6fc14bSjoergprivate: 1842*4d6fc14bSjoerg unsigned char __wd; 1843*4d6fc14bSjoergpublic: 1844*4d6fc14bSjoerg weekday() = default; 1845*4d6fc14bSjoerg inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {} 1846*4d6fc14bSjoerg inline constexpr weekday(const sys_days& __sysd) noexcept 1847*4d6fc14bSjoerg : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {} 1848*4d6fc14bSjoerg inline explicit constexpr weekday(const local_days& __locd) noexcept 1849*4d6fc14bSjoerg : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {} 1850*4d6fc14bSjoerg 1851*4d6fc14bSjoerg inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; } 1852*4d6fc14bSjoerg inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; } 1853*4d6fc14bSjoerg inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; } 1854*4d6fc14bSjoerg inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; } 1855*4d6fc14bSjoerg constexpr weekday& operator+=(const days& __dd) noexcept; 1856*4d6fc14bSjoerg constexpr weekday& operator-=(const days& __dd) noexcept; 1857*4d6fc14bSjoerg inline constexpr unsigned c_encoding() const noexcept { return __wd; } 1858*4d6fc14bSjoerg inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; } 1859*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __wd <= 6; } 1860*4d6fc14bSjoerg constexpr weekday_indexed operator[](unsigned __index) const noexcept; 1861*4d6fc14bSjoerg constexpr weekday_last operator[](last_spec) const noexcept; 1862*4d6fc14bSjoerg 1863*4d6fc14bSjoerg // TODO: Make private? 1864*4d6fc14bSjoerg static constexpr unsigned char __weekday_from_days(int __days) noexcept; 1865*4d6fc14bSjoerg}; 1866*4d6fc14bSjoerg 1867*4d6fc14bSjoerg 1868*4d6fc14bSjoerg// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days 1869*4d6fc14bSjoerginline constexpr 1870*4d6fc14bSjoergunsigned char weekday::__weekday_from_days(int __days) noexcept 1871*4d6fc14bSjoerg{ 1872*4d6fc14bSjoerg return static_cast<unsigned char>( 1873*4d6fc14bSjoerg static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6) 1874*4d6fc14bSjoerg ); 1875*4d6fc14bSjoerg} 1876*4d6fc14bSjoerg 1877*4d6fc14bSjoerginline constexpr 1878*4d6fc14bSjoergbool operator==(const weekday& __lhs, const weekday& __rhs) noexcept 1879*4d6fc14bSjoerg{ return __lhs.c_encoding() == __rhs.c_encoding(); } 1880*4d6fc14bSjoerg 1881*4d6fc14bSjoerginline constexpr 1882*4d6fc14bSjoergbool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept 1883*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 1884*4d6fc14bSjoerg 1885*4d6fc14bSjoerginline constexpr 1886*4d6fc14bSjoergbool operator< (const weekday& __lhs, const weekday& __rhs) noexcept 1887*4d6fc14bSjoerg{ return __lhs.c_encoding() < __rhs.c_encoding(); } 1888*4d6fc14bSjoerg 1889*4d6fc14bSjoerginline constexpr 1890*4d6fc14bSjoergbool operator> (const weekday& __lhs, const weekday& __rhs) noexcept 1891*4d6fc14bSjoerg{ return __rhs < __lhs; } 1892*4d6fc14bSjoerg 1893*4d6fc14bSjoerginline constexpr 1894*4d6fc14bSjoergbool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept 1895*4d6fc14bSjoerg{ return !(__rhs < __lhs);} 1896*4d6fc14bSjoerg 1897*4d6fc14bSjoerginline constexpr 1898*4d6fc14bSjoergbool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept 1899*4d6fc14bSjoerg{ return !(__lhs < __rhs); } 1900*4d6fc14bSjoerg 1901*4d6fc14bSjoergconstexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept 1902*4d6fc14bSjoerg{ 1903*4d6fc14bSjoerg auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count(); 1904*4d6fc14bSjoerg auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; 1905*4d6fc14bSjoerg return weekday{static_cast<unsigned>(__mu - __yr * 7)}; 1906*4d6fc14bSjoerg} 1907*4d6fc14bSjoerg 1908*4d6fc14bSjoergconstexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept 1909*4d6fc14bSjoerg{ return __rhs + __lhs; } 1910*4d6fc14bSjoerg 1911*4d6fc14bSjoergconstexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept 1912*4d6fc14bSjoerg{ return __lhs + -__rhs; } 1913*4d6fc14bSjoerg 1914*4d6fc14bSjoergconstexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept 1915*4d6fc14bSjoerg{ 1916*4d6fc14bSjoerg const int __wdu = __lhs.c_encoding() - __rhs.c_encoding(); 1917*4d6fc14bSjoerg const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7; 1918*4d6fc14bSjoerg return days{__wdu - __wk * 7}; 1919*4d6fc14bSjoerg} 1920*4d6fc14bSjoerg 1921*4d6fc14bSjoerginline constexpr weekday& weekday::operator+=(const days& __dd) noexcept 1922*4d6fc14bSjoerg{ *this = *this + __dd; return *this; } 1923*4d6fc14bSjoerg 1924*4d6fc14bSjoerginline constexpr weekday& weekday::operator-=(const days& __dd) noexcept 1925*4d6fc14bSjoerg{ *this = *this - __dd; return *this; } 1926*4d6fc14bSjoerg 1927*4d6fc14bSjoerg 1928*4d6fc14bSjoergclass weekday_indexed { 1929*4d6fc14bSjoergprivate: 1930*4d6fc14bSjoerg chrono::weekday __wd; 1931*4d6fc14bSjoerg unsigned char __idx; 1932*4d6fc14bSjoergpublic: 1933*4d6fc14bSjoerg weekday_indexed() = default; 1934*4d6fc14bSjoerg inline constexpr weekday_indexed(const chrono::weekday& __wdval, unsigned __idxval) noexcept 1935*4d6fc14bSjoerg : __wd{__wdval}, __idx(__idxval) {} 1936*4d6fc14bSjoerg inline constexpr chrono::weekday weekday() const noexcept { return __wd; } 1937*4d6fc14bSjoerg inline constexpr unsigned index() const noexcept { return __idx; } 1938*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; } 1939*4d6fc14bSjoerg}; 1940*4d6fc14bSjoerg 1941*4d6fc14bSjoerginline constexpr 1942*4d6fc14bSjoergbool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept 1943*4d6fc14bSjoerg{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); } 1944*4d6fc14bSjoerg 1945*4d6fc14bSjoerginline constexpr 1946*4d6fc14bSjoergbool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept 1947*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 1948*4d6fc14bSjoerg 1949*4d6fc14bSjoerg 1950*4d6fc14bSjoergclass weekday_last { 1951*4d6fc14bSjoergprivate: 1952*4d6fc14bSjoerg chrono::weekday __wd; 1953*4d6fc14bSjoergpublic: 1954*4d6fc14bSjoerg explicit constexpr weekday_last(const chrono::weekday& __val) noexcept 1955*4d6fc14bSjoerg : __wd{__val} {} 1956*4d6fc14bSjoerg constexpr chrono::weekday weekday() const noexcept { return __wd; } 1957*4d6fc14bSjoerg constexpr bool ok() const noexcept { return __wd.ok(); } 1958*4d6fc14bSjoerg}; 1959*4d6fc14bSjoerg 1960*4d6fc14bSjoerginline constexpr 1961*4d6fc14bSjoergbool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept 1962*4d6fc14bSjoerg{ return __lhs.weekday() == __rhs.weekday(); } 1963*4d6fc14bSjoerg 1964*4d6fc14bSjoerginline constexpr 1965*4d6fc14bSjoergbool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept 1966*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 1967*4d6fc14bSjoerg 1968*4d6fc14bSjoerginline constexpr 1969*4d6fc14bSjoergweekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; } 1970*4d6fc14bSjoerg 1971*4d6fc14bSjoerginline constexpr 1972*4d6fc14bSjoergweekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; } 1973*4d6fc14bSjoerg 1974*4d6fc14bSjoerg 1975*4d6fc14bSjoerginline constexpr last_spec last{}; 1976*4d6fc14bSjoerginline constexpr weekday Sunday{0}; 1977*4d6fc14bSjoerginline constexpr weekday Monday{1}; 1978*4d6fc14bSjoerginline constexpr weekday Tuesday{2}; 1979*4d6fc14bSjoerginline constexpr weekday Wednesday{3}; 1980*4d6fc14bSjoerginline constexpr weekday Thursday{4}; 1981*4d6fc14bSjoerginline constexpr weekday Friday{5}; 1982*4d6fc14bSjoerginline constexpr weekday Saturday{6}; 1983*4d6fc14bSjoerg 1984*4d6fc14bSjoerginline constexpr month January{1}; 1985*4d6fc14bSjoerginline constexpr month February{2}; 1986*4d6fc14bSjoerginline constexpr month March{3}; 1987*4d6fc14bSjoerginline constexpr month April{4}; 1988*4d6fc14bSjoerginline constexpr month May{5}; 1989*4d6fc14bSjoerginline constexpr month June{6}; 1990*4d6fc14bSjoerginline constexpr month July{7}; 1991*4d6fc14bSjoerginline constexpr month August{8}; 1992*4d6fc14bSjoerginline constexpr month September{9}; 1993*4d6fc14bSjoerginline constexpr month October{10}; 1994*4d6fc14bSjoerginline constexpr month November{11}; 1995*4d6fc14bSjoerginline constexpr month December{12}; 1996*4d6fc14bSjoerg 1997*4d6fc14bSjoerg 1998*4d6fc14bSjoergclass month_day { 1999*4d6fc14bSjoergprivate: 2000*4d6fc14bSjoerg chrono::month __m; 2001*4d6fc14bSjoerg chrono::day __d; 2002*4d6fc14bSjoergpublic: 2003*4d6fc14bSjoerg month_day() = default; 2004*4d6fc14bSjoerg constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept 2005*4d6fc14bSjoerg : __m{__mval}, __d{__dval} {} 2006*4d6fc14bSjoerg inline constexpr chrono::month month() const noexcept { return __m; } 2007*4d6fc14bSjoerg inline constexpr chrono::day day() const noexcept { return __d; } 2008*4d6fc14bSjoerg constexpr bool ok() const noexcept; 2009*4d6fc14bSjoerg}; 2010*4d6fc14bSjoerg 2011*4d6fc14bSjoerginline constexpr 2012*4d6fc14bSjoergbool month_day::ok() const noexcept 2013*4d6fc14bSjoerg{ 2014*4d6fc14bSjoerg if (!__m.ok()) return false; 2015*4d6fc14bSjoerg const unsigned __dval = static_cast<unsigned>(__d); 2016*4d6fc14bSjoerg if (__dval < 1 || __dval > 31) return false; 2017*4d6fc14bSjoerg if (__dval <= 29) return true; 2018*4d6fc14bSjoerg// Now we've got either 30 or 31 2019*4d6fc14bSjoerg const unsigned __mval = static_cast<unsigned>(__m); 2020*4d6fc14bSjoerg if (__mval == 2) return false; 2021*4d6fc14bSjoerg if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) 2022*4d6fc14bSjoerg return __dval == 30; 2023*4d6fc14bSjoerg return true; 2024*4d6fc14bSjoerg} 2025*4d6fc14bSjoerg 2026*4d6fc14bSjoerginline constexpr 2027*4d6fc14bSjoergbool operator==(const month_day& __lhs, const month_day& __rhs) noexcept 2028*4d6fc14bSjoerg{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } 2029*4d6fc14bSjoerg 2030*4d6fc14bSjoerginline constexpr 2031*4d6fc14bSjoergbool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept 2032*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 2033*4d6fc14bSjoerg 2034*4d6fc14bSjoerginline constexpr 2035*4d6fc14bSjoergmonth_day operator/(const month& __lhs, const day& __rhs) noexcept 2036*4d6fc14bSjoerg{ return month_day{__lhs, __rhs}; } 2037*4d6fc14bSjoerg 2038*4d6fc14bSjoergconstexpr 2039*4d6fc14bSjoergmonth_day operator/(const day& __lhs, const month& __rhs) noexcept 2040*4d6fc14bSjoerg{ return __rhs / __lhs; } 2041*4d6fc14bSjoerg 2042*4d6fc14bSjoerginline constexpr 2043*4d6fc14bSjoergmonth_day operator/(const month& __lhs, int __rhs) noexcept 2044*4d6fc14bSjoerg{ return __lhs / day(__rhs); } 2045*4d6fc14bSjoerg 2046*4d6fc14bSjoergconstexpr 2047*4d6fc14bSjoergmonth_day operator/(int __lhs, const day& __rhs) noexcept 2048*4d6fc14bSjoerg{ return month(__lhs) / __rhs; } 2049*4d6fc14bSjoerg 2050*4d6fc14bSjoergconstexpr 2051*4d6fc14bSjoergmonth_day operator/(const day& __lhs, int __rhs) noexcept 2052*4d6fc14bSjoerg{ return month(__rhs) / __lhs; } 2053*4d6fc14bSjoerg 2054*4d6fc14bSjoerg 2055*4d6fc14bSjoerginline constexpr 2056*4d6fc14bSjoergbool operator< (const month_day& __lhs, const month_day& __rhs) noexcept 2057*4d6fc14bSjoerg{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); } 2058*4d6fc14bSjoerg 2059*4d6fc14bSjoerginline constexpr 2060*4d6fc14bSjoergbool operator> (const month_day& __lhs, const month_day& __rhs) noexcept 2061*4d6fc14bSjoerg{ return __rhs < __lhs; } 2062*4d6fc14bSjoerg 2063*4d6fc14bSjoerginline constexpr 2064*4d6fc14bSjoergbool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept 2065*4d6fc14bSjoerg{ return !(__rhs < __lhs);} 2066*4d6fc14bSjoerg 2067*4d6fc14bSjoerginline constexpr 2068*4d6fc14bSjoergbool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept 2069*4d6fc14bSjoerg{ return !(__lhs < __rhs); } 2070*4d6fc14bSjoerg 2071*4d6fc14bSjoerg 2072*4d6fc14bSjoerg 2073*4d6fc14bSjoergclass month_day_last { 2074*4d6fc14bSjoergprivate: 2075*4d6fc14bSjoerg chrono::month __m; 2076*4d6fc14bSjoergpublic: 2077*4d6fc14bSjoerg explicit constexpr month_day_last(const chrono::month& __val) noexcept 2078*4d6fc14bSjoerg : __m{__val} {} 2079*4d6fc14bSjoerg inline constexpr chrono::month month() const noexcept { return __m; } 2080*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __m.ok(); } 2081*4d6fc14bSjoerg}; 2082*4d6fc14bSjoerg 2083*4d6fc14bSjoerginline constexpr 2084*4d6fc14bSjoergbool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 2085*4d6fc14bSjoerg{ return __lhs.month() == __rhs.month(); } 2086*4d6fc14bSjoerg 2087*4d6fc14bSjoerginline constexpr 2088*4d6fc14bSjoergbool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 2089*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 2090*4d6fc14bSjoerg 2091*4d6fc14bSjoerginline constexpr 2092*4d6fc14bSjoergbool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept 2093*4d6fc14bSjoerg{ return __lhs.month() < __rhs.month(); } 2094*4d6fc14bSjoerg 2095*4d6fc14bSjoerginline constexpr 2096*4d6fc14bSjoergbool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept 2097*4d6fc14bSjoerg{ return __rhs < __lhs; } 2098*4d6fc14bSjoerg 2099*4d6fc14bSjoerginline constexpr 2100*4d6fc14bSjoergbool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 2101*4d6fc14bSjoerg{ return !(__rhs < __lhs);} 2102*4d6fc14bSjoerg 2103*4d6fc14bSjoerginline constexpr 2104*4d6fc14bSjoergbool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 2105*4d6fc14bSjoerg{ return !(__lhs < __rhs); } 2106*4d6fc14bSjoerg 2107*4d6fc14bSjoerginline constexpr 2108*4d6fc14bSjoergmonth_day_last operator/(const month& __lhs, last_spec) noexcept 2109*4d6fc14bSjoerg{ return month_day_last{__lhs}; } 2110*4d6fc14bSjoerg 2111*4d6fc14bSjoerginline constexpr 2112*4d6fc14bSjoergmonth_day_last operator/(last_spec, const month& __rhs) noexcept 2113*4d6fc14bSjoerg{ return month_day_last{__rhs}; } 2114*4d6fc14bSjoerg 2115*4d6fc14bSjoerginline constexpr 2116*4d6fc14bSjoergmonth_day_last operator/(int __lhs, last_spec) noexcept 2117*4d6fc14bSjoerg{ return month_day_last{month(__lhs)}; } 2118*4d6fc14bSjoerg 2119*4d6fc14bSjoerginline constexpr 2120*4d6fc14bSjoergmonth_day_last operator/(last_spec, int __rhs) noexcept 2121*4d6fc14bSjoerg{ return month_day_last{month(__rhs)}; } 2122*4d6fc14bSjoerg 2123*4d6fc14bSjoerg 2124*4d6fc14bSjoergclass month_weekday { 2125*4d6fc14bSjoergprivate: 2126*4d6fc14bSjoerg chrono::month __m; 2127*4d6fc14bSjoerg chrono::weekday_indexed __wdi; 2128*4d6fc14bSjoergpublic: 2129*4d6fc14bSjoerg month_weekday() = default; 2130*4d6fc14bSjoerg constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept 2131*4d6fc14bSjoerg : __m{__mval}, __wdi{__wdival} {} 2132*4d6fc14bSjoerg inline constexpr chrono::month month() const noexcept { return __m; } 2133*4d6fc14bSjoerg inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } 2134*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); } 2135*4d6fc14bSjoerg}; 2136*4d6fc14bSjoerg 2137*4d6fc14bSjoerginline constexpr 2138*4d6fc14bSjoergbool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept 2139*4d6fc14bSjoerg{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } 2140*4d6fc14bSjoerg 2141*4d6fc14bSjoerginline constexpr 2142*4d6fc14bSjoergbool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept 2143*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 2144*4d6fc14bSjoerg 2145*4d6fc14bSjoerginline constexpr 2146*4d6fc14bSjoergmonth_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept 2147*4d6fc14bSjoerg{ return month_weekday{__lhs, __rhs}; } 2148*4d6fc14bSjoerg 2149*4d6fc14bSjoerginline constexpr 2150*4d6fc14bSjoergmonth_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept 2151*4d6fc14bSjoerg{ return month_weekday{month(__lhs), __rhs}; } 2152*4d6fc14bSjoerg 2153*4d6fc14bSjoerginline constexpr 2154*4d6fc14bSjoergmonth_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept 2155*4d6fc14bSjoerg{ return month_weekday{__rhs, __lhs}; } 2156*4d6fc14bSjoerg 2157*4d6fc14bSjoerginline constexpr 2158*4d6fc14bSjoergmonth_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept 2159*4d6fc14bSjoerg{ return month_weekday{month(__rhs), __lhs}; } 2160*4d6fc14bSjoerg 2161*4d6fc14bSjoerg 2162*4d6fc14bSjoergclass month_weekday_last { 2163*4d6fc14bSjoerg chrono::month __m; 2164*4d6fc14bSjoerg chrono::weekday_last __wdl; 2165*4d6fc14bSjoerg public: 2166*4d6fc14bSjoerg constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept 2167*4d6fc14bSjoerg : __m{__mval}, __wdl{__wdlval} {} 2168*4d6fc14bSjoerg inline constexpr chrono::month month() const noexcept { return __m; } 2169*4d6fc14bSjoerg inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } 2170*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); } 2171*4d6fc14bSjoerg}; 2172*4d6fc14bSjoerg 2173*4d6fc14bSjoerginline constexpr 2174*4d6fc14bSjoergbool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept 2175*4d6fc14bSjoerg{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } 2176*4d6fc14bSjoerg 2177*4d6fc14bSjoerginline constexpr 2178*4d6fc14bSjoergbool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept 2179*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 2180*4d6fc14bSjoerg 2181*4d6fc14bSjoerg 2182*4d6fc14bSjoerginline constexpr 2183*4d6fc14bSjoergmonth_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept 2184*4d6fc14bSjoerg{ return month_weekday_last{__lhs, __rhs}; } 2185*4d6fc14bSjoerg 2186*4d6fc14bSjoerginline constexpr 2187*4d6fc14bSjoergmonth_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept 2188*4d6fc14bSjoerg{ return month_weekday_last{month(__lhs), __rhs}; } 2189*4d6fc14bSjoerg 2190*4d6fc14bSjoerginline constexpr 2191*4d6fc14bSjoergmonth_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept 2192*4d6fc14bSjoerg{ return month_weekday_last{__rhs, __lhs}; } 2193*4d6fc14bSjoerg 2194*4d6fc14bSjoerginline constexpr 2195*4d6fc14bSjoergmonth_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept 2196*4d6fc14bSjoerg{ return month_weekday_last{month(__rhs), __lhs}; } 2197*4d6fc14bSjoerg 2198*4d6fc14bSjoerg 2199*4d6fc14bSjoergclass year_month { 2200*4d6fc14bSjoerg chrono::year __y; 2201*4d6fc14bSjoerg chrono::month __m; 2202*4d6fc14bSjoergpublic: 2203*4d6fc14bSjoerg year_month() = default; 2204*4d6fc14bSjoerg constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept 2205*4d6fc14bSjoerg : __y{__yval}, __m{__mval} {} 2206*4d6fc14bSjoerg inline constexpr chrono::year year() const noexcept { return __y; } 2207*4d6fc14bSjoerg inline constexpr chrono::month month() const noexcept { return __m; } 2208*4d6fc14bSjoerg inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; } 2209*4d6fc14bSjoerg inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; } 2210*4d6fc14bSjoerg inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; } 2211*4d6fc14bSjoerg inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; } 2212*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); } 2213*4d6fc14bSjoerg}; 2214*4d6fc14bSjoerg 2215*4d6fc14bSjoerginline constexpr 2216*4d6fc14bSjoergyear_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; } 2217*4d6fc14bSjoerg 2218*4d6fc14bSjoerginline constexpr 2219*4d6fc14bSjoergyear_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; } 2220*4d6fc14bSjoerg 2221*4d6fc14bSjoerginline constexpr 2222*4d6fc14bSjoergbool operator==(const year_month& __lhs, const year_month& __rhs) noexcept 2223*4d6fc14bSjoerg{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); } 2224*4d6fc14bSjoerg 2225*4d6fc14bSjoerginline constexpr 2226*4d6fc14bSjoergbool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept 2227*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 2228*4d6fc14bSjoerg 2229*4d6fc14bSjoerginline constexpr 2230*4d6fc14bSjoergbool operator< (const year_month& __lhs, const year_month& __rhs) noexcept 2231*4d6fc14bSjoerg{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); } 2232*4d6fc14bSjoerg 2233*4d6fc14bSjoerginline constexpr 2234*4d6fc14bSjoergbool operator> (const year_month& __lhs, const year_month& __rhs) noexcept 2235*4d6fc14bSjoerg{ return __rhs < __lhs; } 2236*4d6fc14bSjoerg 2237*4d6fc14bSjoerginline constexpr 2238*4d6fc14bSjoergbool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept 2239*4d6fc14bSjoerg{ return !(__rhs < __lhs);} 2240*4d6fc14bSjoerg 2241*4d6fc14bSjoerginline constexpr 2242*4d6fc14bSjoergbool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept 2243*4d6fc14bSjoerg{ return !(__lhs < __rhs); } 2244*4d6fc14bSjoerg 2245*4d6fc14bSjoergconstexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept 2246*4d6fc14bSjoerg{ 2247*4d6fc14bSjoerg int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count(); 2248*4d6fc14bSjoerg const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12; 2249*4d6fc14bSjoerg __dmi = __dmi - __dy * 12 + 1; 2250*4d6fc14bSjoerg return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi)); 2251*4d6fc14bSjoerg} 2252*4d6fc14bSjoerg 2253*4d6fc14bSjoergconstexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept 2254*4d6fc14bSjoerg{ return __rhs + __lhs; } 2255*4d6fc14bSjoerg 2256*4d6fc14bSjoergconstexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept 2257*4d6fc14bSjoerg{ return (__lhs.year() + __rhs) / __lhs.month(); } 2258*4d6fc14bSjoerg 2259*4d6fc14bSjoergconstexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept 2260*4d6fc14bSjoerg{ return __rhs + __lhs; } 2261*4d6fc14bSjoerg 2262*4d6fc14bSjoergconstexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept 2263*4d6fc14bSjoerg{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); } 2264*4d6fc14bSjoerg 2265*4d6fc14bSjoergconstexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept 2266*4d6fc14bSjoerg{ return __lhs + -__rhs; } 2267*4d6fc14bSjoerg 2268*4d6fc14bSjoergconstexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept 2269*4d6fc14bSjoerg{ return __lhs + -__rhs; } 2270*4d6fc14bSjoerg 2271*4d6fc14bSjoergclass year_month_day_last; 2272*4d6fc14bSjoerg 2273*4d6fc14bSjoergclass year_month_day { 2274*4d6fc14bSjoergprivate: 2275*4d6fc14bSjoerg chrono::year __y; 2276*4d6fc14bSjoerg chrono::month __m; 2277*4d6fc14bSjoerg chrono::day __d; 2278*4d6fc14bSjoergpublic: 2279*4d6fc14bSjoerg year_month_day() = default; 2280*4d6fc14bSjoerg inline constexpr year_month_day( 2281*4d6fc14bSjoerg const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept 2282*4d6fc14bSjoerg : __y{__yval}, __m{__mval}, __d{__dval} {} 2283*4d6fc14bSjoerg constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; 2284*4d6fc14bSjoerg inline constexpr year_month_day(const sys_days& __sysd) noexcept 2285*4d6fc14bSjoerg : year_month_day(__from_days(__sysd.time_since_epoch())) {} 2286*4d6fc14bSjoerg inline explicit constexpr year_month_day(const local_days& __locd) noexcept 2287*4d6fc14bSjoerg : year_month_day(__from_days(__locd.time_since_epoch())) {} 2288*4d6fc14bSjoerg 2289*4d6fc14bSjoerg constexpr year_month_day& operator+=(const months& __dm) noexcept; 2290*4d6fc14bSjoerg constexpr year_month_day& operator-=(const months& __dm) noexcept; 2291*4d6fc14bSjoerg constexpr year_month_day& operator+=(const years& __dy) noexcept; 2292*4d6fc14bSjoerg constexpr year_month_day& operator-=(const years& __dy) noexcept; 2293*4d6fc14bSjoerg 2294*4d6fc14bSjoerg inline constexpr chrono::year year() const noexcept { return __y; } 2295*4d6fc14bSjoerg inline constexpr chrono::month month() const noexcept { return __m; } 2296*4d6fc14bSjoerg inline constexpr chrono::day day() const noexcept { return __d; } 2297*4d6fc14bSjoerg inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } 2298*4d6fc14bSjoerg inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } 2299*4d6fc14bSjoerg 2300*4d6fc14bSjoerg constexpr bool ok() const noexcept; 2301*4d6fc14bSjoerg 2302*4d6fc14bSjoerg static constexpr year_month_day __from_days(days __d) noexcept; 2303*4d6fc14bSjoerg constexpr days __to_days() const noexcept; 2304*4d6fc14bSjoerg}; 2305*4d6fc14bSjoerg 2306*4d6fc14bSjoerg 2307*4d6fc14bSjoerg// https://howardhinnant.github.io/date_algorithms.html#civil_from_days 2308*4d6fc14bSjoerginline constexpr 2309*4d6fc14bSjoergyear_month_day 2310*4d6fc14bSjoergyear_month_day::__from_days(days __d) noexcept 2311*4d6fc14bSjoerg{ 2312*4d6fc14bSjoerg static_assert(numeric_limits<unsigned>::digits >= 18, ""); 2313*4d6fc14bSjoerg static_assert(numeric_limits<int>::digits >= 20 , ""); 2314*4d6fc14bSjoerg const int __z = __d.count() + 719468; 2315*4d6fc14bSjoerg const int __era = (__z >= 0 ? __z : __z - 146096) / 146097; 2316*4d6fc14bSjoerg const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096] 2317*4d6fc14bSjoerg const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399] 2318*4d6fc14bSjoerg const int __yr = static_cast<int>(__yoe) + __era * 400; 2319*4d6fc14bSjoerg const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365] 2320*4d6fc14bSjoerg const unsigned __mp = (5 * __doy + 2)/153; // [0, 11] 2321*4d6fc14bSjoerg const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31] 2322*4d6fc14bSjoerg const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12] 2323*4d6fc14bSjoerg return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}}; 2324*4d6fc14bSjoerg} 2325*4d6fc14bSjoerg 2326*4d6fc14bSjoerg// https://howardhinnant.github.io/date_algorithms.html#days_from_civil 2327*4d6fc14bSjoerginline constexpr days year_month_day::__to_days() const noexcept 2328*4d6fc14bSjoerg{ 2329*4d6fc14bSjoerg static_assert(numeric_limits<unsigned>::digits >= 18, ""); 2330*4d6fc14bSjoerg static_assert(numeric_limits<int>::digits >= 20 , ""); 2331*4d6fc14bSjoerg 2332*4d6fc14bSjoerg const int __yr = static_cast<int>(__y) - (__m <= February); 2333*4d6fc14bSjoerg const unsigned __mth = static_cast<unsigned>(__m); 2334*4d6fc14bSjoerg const unsigned __dy = static_cast<unsigned>(__d); 2335*4d6fc14bSjoerg 2336*4d6fc14bSjoerg const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400; 2337*4d6fc14bSjoerg const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399] 2338*4d6fc14bSjoerg const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365] 2339*4d6fc14bSjoerg const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096] 2340*4d6fc14bSjoerg return days{__era * 146097 + static_cast<int>(__doe) - 719468}; 2341*4d6fc14bSjoerg} 2342*4d6fc14bSjoerg 2343*4d6fc14bSjoerginline constexpr 2344*4d6fc14bSjoergbool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept 2345*4d6fc14bSjoerg{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } 2346*4d6fc14bSjoerg 2347*4d6fc14bSjoerginline constexpr 2348*4d6fc14bSjoergbool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept 2349*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 2350*4d6fc14bSjoerg 2351*4d6fc14bSjoerginline constexpr 2352*4d6fc14bSjoergbool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept 2353*4d6fc14bSjoerg{ 2354*4d6fc14bSjoerg if (__lhs.year() < __rhs.year()) return true; 2355*4d6fc14bSjoerg if (__lhs.year() > __rhs.year()) return false; 2356*4d6fc14bSjoerg if (__lhs.month() < __rhs.month()) return true; 2357*4d6fc14bSjoerg if (__lhs.month() > __rhs.month()) return false; 2358*4d6fc14bSjoerg return __lhs.day() < __rhs.day(); 2359*4d6fc14bSjoerg} 2360*4d6fc14bSjoerg 2361*4d6fc14bSjoerginline constexpr 2362*4d6fc14bSjoergbool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept 2363*4d6fc14bSjoerg{ return __rhs < __lhs; } 2364*4d6fc14bSjoerg 2365*4d6fc14bSjoerginline constexpr 2366*4d6fc14bSjoergbool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept 2367*4d6fc14bSjoerg{ return !(__rhs < __lhs);} 2368*4d6fc14bSjoerg 2369*4d6fc14bSjoerginline constexpr 2370*4d6fc14bSjoergbool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept 2371*4d6fc14bSjoerg{ return !(__lhs < __rhs); } 2372*4d6fc14bSjoerg 2373*4d6fc14bSjoerginline constexpr 2374*4d6fc14bSjoergyear_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept 2375*4d6fc14bSjoerg{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; } 2376*4d6fc14bSjoerg 2377*4d6fc14bSjoerginline constexpr 2378*4d6fc14bSjoergyear_month_day operator/(const year_month& __lhs, int __rhs) noexcept 2379*4d6fc14bSjoerg{ return __lhs / day(__rhs); } 2380*4d6fc14bSjoerg 2381*4d6fc14bSjoerginline constexpr 2382*4d6fc14bSjoergyear_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept 2383*4d6fc14bSjoerg{ return __lhs / __rhs.month() / __rhs.day(); } 2384*4d6fc14bSjoerg 2385*4d6fc14bSjoerginline constexpr 2386*4d6fc14bSjoergyear_month_day operator/(int __lhs, const month_day& __rhs) noexcept 2387*4d6fc14bSjoerg{ return year(__lhs) / __rhs; } 2388*4d6fc14bSjoerg 2389*4d6fc14bSjoerginline constexpr 2390*4d6fc14bSjoergyear_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept 2391*4d6fc14bSjoerg{ return __rhs / __lhs; } 2392*4d6fc14bSjoerg 2393*4d6fc14bSjoerginline constexpr 2394*4d6fc14bSjoergyear_month_day operator/(const month_day& __lhs, int __rhs) noexcept 2395*4d6fc14bSjoerg{ return year(__rhs) / __lhs; } 2396*4d6fc14bSjoerg 2397*4d6fc14bSjoerg 2398*4d6fc14bSjoerginline constexpr 2399*4d6fc14bSjoergyear_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept 2400*4d6fc14bSjoerg{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); } 2401*4d6fc14bSjoerg 2402*4d6fc14bSjoerginline constexpr 2403*4d6fc14bSjoergyear_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept 2404*4d6fc14bSjoerg{ return __rhs + __lhs; } 2405*4d6fc14bSjoerg 2406*4d6fc14bSjoerginline constexpr 2407*4d6fc14bSjoergyear_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept 2408*4d6fc14bSjoerg{ return __lhs + -__rhs; } 2409*4d6fc14bSjoerg 2410*4d6fc14bSjoerginline constexpr 2411*4d6fc14bSjoergyear_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept 2412*4d6fc14bSjoerg{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); } 2413*4d6fc14bSjoerg 2414*4d6fc14bSjoerginline constexpr 2415*4d6fc14bSjoergyear_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept 2416*4d6fc14bSjoerg{ return __rhs + __lhs; } 2417*4d6fc14bSjoerg 2418*4d6fc14bSjoerginline constexpr 2419*4d6fc14bSjoergyear_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept 2420*4d6fc14bSjoerg{ return __lhs + -__rhs; } 2421*4d6fc14bSjoerg 2422*4d6fc14bSjoerginline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } 2423*4d6fc14bSjoerginline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } 2424*4d6fc14bSjoerginline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } 2425*4d6fc14bSjoerginline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } 2426*4d6fc14bSjoerg 2427*4d6fc14bSjoergclass year_month_day_last { 2428*4d6fc14bSjoergprivate: 2429*4d6fc14bSjoerg chrono::year __y; 2430*4d6fc14bSjoerg chrono::month_day_last __mdl; 2431*4d6fc14bSjoergpublic: 2432*4d6fc14bSjoerg constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept 2433*4d6fc14bSjoerg : __y{__yval}, __mdl{__mdlval} {} 2434*4d6fc14bSjoerg 2435*4d6fc14bSjoerg constexpr year_month_day_last& operator+=(const months& __m) noexcept; 2436*4d6fc14bSjoerg constexpr year_month_day_last& operator-=(const months& __m) noexcept; 2437*4d6fc14bSjoerg constexpr year_month_day_last& operator+=(const years& __y) noexcept; 2438*4d6fc14bSjoerg constexpr year_month_day_last& operator-=(const years& __y) noexcept; 2439*4d6fc14bSjoerg 2440*4d6fc14bSjoerg inline constexpr chrono::year year() const noexcept { return __y; } 2441*4d6fc14bSjoerg inline constexpr chrono::month month() const noexcept { return __mdl.month(); } 2442*4d6fc14bSjoerg inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; } 2443*4d6fc14bSjoerg constexpr chrono::day day() const noexcept; 2444*4d6fc14bSjoerg inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; } 2445*4d6fc14bSjoerg inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; } 2446*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); } 2447*4d6fc14bSjoerg}; 2448*4d6fc14bSjoerg 2449*4d6fc14bSjoerginline constexpr 2450*4d6fc14bSjoergchrono::day year_month_day_last::day() const noexcept 2451*4d6fc14bSjoerg{ 2452*4d6fc14bSjoerg constexpr chrono::day __d[] = 2453*4d6fc14bSjoerg { 2454*4d6fc14bSjoerg chrono::day(31), chrono::day(28), chrono::day(31), 2455*4d6fc14bSjoerg chrono::day(30), chrono::day(31), chrono::day(30), 2456*4d6fc14bSjoerg chrono::day(31), chrono::day(31), chrono::day(30), 2457*4d6fc14bSjoerg chrono::day(31), chrono::day(30), chrono::day(31) 2458*4d6fc14bSjoerg }; 2459*4d6fc14bSjoerg return (month() != February || !__y.is_leap()) && month().ok() ? 2460*4d6fc14bSjoerg __d[static_cast<unsigned>(month()) - 1] : chrono::day{29}; 2461*4d6fc14bSjoerg} 2462*4d6fc14bSjoerg 2463*4d6fc14bSjoerginline constexpr 2464*4d6fc14bSjoergbool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 2465*4d6fc14bSjoerg{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); } 2466*4d6fc14bSjoerg 2467*4d6fc14bSjoerginline constexpr 2468*4d6fc14bSjoergbool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 2469*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 2470*4d6fc14bSjoerg 2471*4d6fc14bSjoerginline constexpr 2472*4d6fc14bSjoergbool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 2473*4d6fc14bSjoerg{ 2474*4d6fc14bSjoerg if (__lhs.year() < __rhs.year()) return true; 2475*4d6fc14bSjoerg if (__lhs.year() > __rhs.year()) return false; 2476*4d6fc14bSjoerg return __lhs.month_day_last() < __rhs.month_day_last(); 2477*4d6fc14bSjoerg} 2478*4d6fc14bSjoerg 2479*4d6fc14bSjoerginline constexpr 2480*4d6fc14bSjoergbool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 2481*4d6fc14bSjoerg{ return __rhs < __lhs; } 2482*4d6fc14bSjoerg 2483*4d6fc14bSjoerginline constexpr 2484*4d6fc14bSjoergbool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 2485*4d6fc14bSjoerg{ return !(__rhs < __lhs);} 2486*4d6fc14bSjoerg 2487*4d6fc14bSjoerginline constexpr 2488*4d6fc14bSjoergbool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 2489*4d6fc14bSjoerg{ return !(__lhs < __rhs); } 2490*4d6fc14bSjoerg 2491*4d6fc14bSjoerginline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept 2492*4d6fc14bSjoerg{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; } 2493*4d6fc14bSjoerg 2494*4d6fc14bSjoerginline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept 2495*4d6fc14bSjoerg{ return year_month_day_last{__lhs, __rhs}; } 2496*4d6fc14bSjoerg 2497*4d6fc14bSjoerginline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept 2498*4d6fc14bSjoerg{ return year_month_day_last{year{__lhs}, __rhs}; } 2499*4d6fc14bSjoerg 2500*4d6fc14bSjoerginline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept 2501*4d6fc14bSjoerg{ return __rhs / __lhs; } 2502*4d6fc14bSjoerg 2503*4d6fc14bSjoerginline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept 2504*4d6fc14bSjoerg{ return year{__rhs} / __lhs; } 2505*4d6fc14bSjoerg 2506*4d6fc14bSjoerg 2507*4d6fc14bSjoerginline constexpr 2508*4d6fc14bSjoergyear_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept 2509*4d6fc14bSjoerg{ return (__lhs.year() / __lhs.month() + __rhs) / last; } 2510*4d6fc14bSjoerg 2511*4d6fc14bSjoerginline constexpr 2512*4d6fc14bSjoergyear_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept 2513*4d6fc14bSjoerg{ return __rhs + __lhs; } 2514*4d6fc14bSjoerg 2515*4d6fc14bSjoerginline constexpr 2516*4d6fc14bSjoergyear_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept 2517*4d6fc14bSjoerg{ return __lhs + (-__rhs); } 2518*4d6fc14bSjoerg 2519*4d6fc14bSjoerginline constexpr 2520*4d6fc14bSjoergyear_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept 2521*4d6fc14bSjoerg{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; } 2522*4d6fc14bSjoerg 2523*4d6fc14bSjoerginline constexpr 2524*4d6fc14bSjoergyear_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept 2525*4d6fc14bSjoerg{ return __rhs + __lhs; } 2526*4d6fc14bSjoerg 2527*4d6fc14bSjoerginline constexpr 2528*4d6fc14bSjoergyear_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept 2529*4d6fc14bSjoerg{ return __lhs + (-__rhs); } 2530*4d6fc14bSjoerg 2531*4d6fc14bSjoerginline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } 2532*4d6fc14bSjoerginline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } 2533*4d6fc14bSjoerginline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } 2534*4d6fc14bSjoerginline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } 2535*4d6fc14bSjoerg 2536*4d6fc14bSjoerginline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept 2537*4d6fc14bSjoerg : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {} 2538*4d6fc14bSjoerg 2539*4d6fc14bSjoerginline constexpr bool year_month_day::ok() const noexcept 2540*4d6fc14bSjoerg{ 2541*4d6fc14bSjoerg if (!__y.ok() || !__m.ok()) return false; 2542*4d6fc14bSjoerg return chrono::day{1} <= __d && __d <= (__y / __m / last).day(); 2543*4d6fc14bSjoerg} 2544*4d6fc14bSjoerg 2545*4d6fc14bSjoergclass year_month_weekday { 2546*4d6fc14bSjoerg chrono::year __y; 2547*4d6fc14bSjoerg chrono::month __m; 2548*4d6fc14bSjoerg chrono::weekday_indexed __wdi; 2549*4d6fc14bSjoergpublic: 2550*4d6fc14bSjoerg year_month_weekday() = default; 2551*4d6fc14bSjoerg constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval, 2552*4d6fc14bSjoerg const chrono::weekday_indexed& __wdival) noexcept 2553*4d6fc14bSjoerg : __y{__yval}, __m{__mval}, __wdi{__wdival} {} 2554*4d6fc14bSjoerg constexpr year_month_weekday(const sys_days& __sysd) noexcept 2555*4d6fc14bSjoerg : year_month_weekday(__from_days(__sysd.time_since_epoch())) {} 2556*4d6fc14bSjoerg inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept 2557*4d6fc14bSjoerg : year_month_weekday(__from_days(__locd.time_since_epoch())) {} 2558*4d6fc14bSjoerg constexpr year_month_weekday& operator+=(const months& m) noexcept; 2559*4d6fc14bSjoerg constexpr year_month_weekday& operator-=(const months& m) noexcept; 2560*4d6fc14bSjoerg constexpr year_month_weekday& operator+=(const years& y) noexcept; 2561*4d6fc14bSjoerg constexpr year_month_weekday& operator-=(const years& y) noexcept; 2562*4d6fc14bSjoerg 2563*4d6fc14bSjoerg inline constexpr chrono::year year() const noexcept { return __y; } 2564*4d6fc14bSjoerg inline constexpr chrono::month month() const noexcept { return __m; } 2565*4d6fc14bSjoerg inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); } 2566*4d6fc14bSjoerg inline constexpr unsigned index() const noexcept { return __wdi.index(); } 2567*4d6fc14bSjoerg inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } 2568*4d6fc14bSjoerg 2569*4d6fc14bSjoerg inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } 2570*4d6fc14bSjoerg inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } 2571*4d6fc14bSjoerg inline constexpr bool ok() const noexcept 2572*4d6fc14bSjoerg { 2573*4d6fc14bSjoerg if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false; 2574*4d6fc14bSjoerg if (__wdi.index() <= 4) return true; 2575*4d6fc14bSjoerg auto __nth_weekday_day = 2576*4d6fc14bSjoerg __wdi.weekday() - 2577*4d6fc14bSjoerg chrono::weekday{static_cast<sys_days>(__y / __m / 1)} + 2578*4d6fc14bSjoerg days{(__wdi.index() - 1) * 7 + 1}; 2579*4d6fc14bSjoerg return static_cast<unsigned>(__nth_weekday_day.count()) <= 2580*4d6fc14bSjoerg static_cast<unsigned>((__y / __m / last).day()); 2581*4d6fc14bSjoerg } 2582*4d6fc14bSjoerg 2583*4d6fc14bSjoerg static constexpr year_month_weekday __from_days(days __d) noexcept; 2584*4d6fc14bSjoerg constexpr days __to_days() const noexcept; 2585*4d6fc14bSjoerg}; 2586*4d6fc14bSjoerg 2587*4d6fc14bSjoerginline constexpr 2588*4d6fc14bSjoergyear_month_weekday year_month_weekday::__from_days(days __d) noexcept 2589*4d6fc14bSjoerg{ 2590*4d6fc14bSjoerg const sys_days __sysd{__d}; 2591*4d6fc14bSjoerg const chrono::weekday __wd = chrono::weekday(__sysd); 2592*4d6fc14bSjoerg const year_month_day __ymd = year_month_day(__sysd); 2593*4d6fc14bSjoerg return year_month_weekday{__ymd.year(), __ymd.month(), 2594*4d6fc14bSjoerg __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]}; 2595*4d6fc14bSjoerg} 2596*4d6fc14bSjoerg 2597*4d6fc14bSjoerginline constexpr 2598*4d6fc14bSjoergdays year_month_weekday::__to_days() const noexcept 2599*4d6fc14bSjoerg{ 2600*4d6fc14bSjoerg const sys_days __sysd = sys_days(__y/__m/1); 2601*4d6fc14bSjoerg return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7})) 2602*4d6fc14bSjoerg .time_since_epoch(); 2603*4d6fc14bSjoerg} 2604*4d6fc14bSjoerg 2605*4d6fc14bSjoerginline constexpr 2606*4d6fc14bSjoergbool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept 2607*4d6fc14bSjoerg{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } 2608*4d6fc14bSjoerg 2609*4d6fc14bSjoerginline constexpr 2610*4d6fc14bSjoergbool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept 2611*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 2612*4d6fc14bSjoerg 2613*4d6fc14bSjoerginline constexpr 2614*4d6fc14bSjoergyear_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept 2615*4d6fc14bSjoerg{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; } 2616*4d6fc14bSjoerg 2617*4d6fc14bSjoerginline constexpr 2618*4d6fc14bSjoergyear_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept 2619*4d6fc14bSjoerg{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; } 2620*4d6fc14bSjoerg 2621*4d6fc14bSjoerginline constexpr 2622*4d6fc14bSjoergyear_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept 2623*4d6fc14bSjoerg{ return year(__lhs) / __rhs; } 2624*4d6fc14bSjoerg 2625*4d6fc14bSjoerginline constexpr 2626*4d6fc14bSjoergyear_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept 2627*4d6fc14bSjoerg{ return __rhs / __lhs; } 2628*4d6fc14bSjoerg 2629*4d6fc14bSjoerginline constexpr 2630*4d6fc14bSjoergyear_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept 2631*4d6fc14bSjoerg{ return year(__rhs) / __lhs; } 2632*4d6fc14bSjoerg 2633*4d6fc14bSjoerg 2634*4d6fc14bSjoerginline constexpr 2635*4d6fc14bSjoergyear_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept 2636*4d6fc14bSjoerg{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); } 2637*4d6fc14bSjoerg 2638*4d6fc14bSjoerginline constexpr 2639*4d6fc14bSjoergyear_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept 2640*4d6fc14bSjoerg{ return __rhs + __lhs; } 2641*4d6fc14bSjoerg 2642*4d6fc14bSjoerginline constexpr 2643*4d6fc14bSjoergyear_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept 2644*4d6fc14bSjoerg{ return __lhs + (-__rhs); } 2645*4d6fc14bSjoerg 2646*4d6fc14bSjoerginline constexpr 2647*4d6fc14bSjoergyear_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept 2648*4d6fc14bSjoerg{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; } 2649*4d6fc14bSjoerg 2650*4d6fc14bSjoerginline constexpr 2651*4d6fc14bSjoergyear_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept 2652*4d6fc14bSjoerg{ return __rhs + __lhs; } 2653*4d6fc14bSjoerg 2654*4d6fc14bSjoerginline constexpr 2655*4d6fc14bSjoergyear_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept 2656*4d6fc14bSjoerg{ return __lhs + (-__rhs); } 2657*4d6fc14bSjoerg 2658*4d6fc14bSjoerg 2659*4d6fc14bSjoerginline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } 2660*4d6fc14bSjoerginline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } 2661*4d6fc14bSjoerginline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } 2662*4d6fc14bSjoerginline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } 2663*4d6fc14bSjoerg 2664*4d6fc14bSjoergclass year_month_weekday_last { 2665*4d6fc14bSjoergprivate: 2666*4d6fc14bSjoerg chrono::year __y; 2667*4d6fc14bSjoerg chrono::month __m; 2668*4d6fc14bSjoerg chrono::weekday_last __wdl; 2669*4d6fc14bSjoergpublic: 2670*4d6fc14bSjoerg constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval, 2671*4d6fc14bSjoerg const chrono::weekday_last& __wdlval) noexcept 2672*4d6fc14bSjoerg : __y{__yval}, __m{__mval}, __wdl{__wdlval} {} 2673*4d6fc14bSjoerg constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept; 2674*4d6fc14bSjoerg constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept; 2675*4d6fc14bSjoerg constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept; 2676*4d6fc14bSjoerg constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept; 2677*4d6fc14bSjoerg 2678*4d6fc14bSjoerg inline constexpr chrono::year year() const noexcept { return __y; } 2679*4d6fc14bSjoerg inline constexpr chrono::month month() const noexcept { return __m; } 2680*4d6fc14bSjoerg inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); } 2681*4d6fc14bSjoerg inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } 2682*4d6fc14bSjoerg inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } 2683*4d6fc14bSjoerg inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } 2684*4d6fc14bSjoerg inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); } 2685*4d6fc14bSjoerg 2686*4d6fc14bSjoerg constexpr days __to_days() const noexcept; 2687*4d6fc14bSjoerg 2688*4d6fc14bSjoerg}; 2689*4d6fc14bSjoerg 2690*4d6fc14bSjoerginline constexpr 2691*4d6fc14bSjoergdays year_month_weekday_last::__to_days() const noexcept 2692*4d6fc14bSjoerg{ 2693*4d6fc14bSjoerg const sys_days __last = sys_days{__y/__m/last}; 2694*4d6fc14bSjoerg return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch(); 2695*4d6fc14bSjoerg 2696*4d6fc14bSjoerg} 2697*4d6fc14bSjoerg 2698*4d6fc14bSjoerginline constexpr 2699*4d6fc14bSjoergbool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept 2700*4d6fc14bSjoerg{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } 2701*4d6fc14bSjoerg 2702*4d6fc14bSjoerginline constexpr 2703*4d6fc14bSjoergbool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept 2704*4d6fc14bSjoerg{ return !(__lhs == __rhs); } 2705*4d6fc14bSjoerg 2706*4d6fc14bSjoerg 2707*4d6fc14bSjoerginline constexpr 2708*4d6fc14bSjoergyear_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept 2709*4d6fc14bSjoerg{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; } 2710*4d6fc14bSjoerg 2711*4d6fc14bSjoerginline constexpr 2712*4d6fc14bSjoergyear_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept 2713*4d6fc14bSjoerg{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; } 2714*4d6fc14bSjoerg 2715*4d6fc14bSjoerginline constexpr 2716*4d6fc14bSjoergyear_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept 2717*4d6fc14bSjoerg{ return year(__lhs) / __rhs; } 2718*4d6fc14bSjoerg 2719*4d6fc14bSjoerginline constexpr 2720*4d6fc14bSjoergyear_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept 2721*4d6fc14bSjoerg{ return __rhs / __lhs; } 2722*4d6fc14bSjoerg 2723*4d6fc14bSjoerginline constexpr 2724*4d6fc14bSjoergyear_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept 2725*4d6fc14bSjoerg{ return year(__rhs) / __lhs; } 2726*4d6fc14bSjoerg 2727*4d6fc14bSjoerg 2728*4d6fc14bSjoerginline constexpr 2729*4d6fc14bSjoergyear_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept 2730*4d6fc14bSjoerg{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); } 2731*4d6fc14bSjoerg 2732*4d6fc14bSjoerginline constexpr 2733*4d6fc14bSjoergyear_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept 2734*4d6fc14bSjoerg{ return __rhs + __lhs; } 2735*4d6fc14bSjoerg 2736*4d6fc14bSjoerginline constexpr 2737*4d6fc14bSjoergyear_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept 2738*4d6fc14bSjoerg{ return __lhs + (-__rhs); } 2739*4d6fc14bSjoerg 2740*4d6fc14bSjoerginline constexpr 2741*4d6fc14bSjoergyear_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept 2742*4d6fc14bSjoerg{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; } 2743*4d6fc14bSjoerg 2744*4d6fc14bSjoerginline constexpr 2745*4d6fc14bSjoergyear_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept 2746*4d6fc14bSjoerg{ return __rhs + __lhs; } 2747*4d6fc14bSjoerg 2748*4d6fc14bSjoerginline constexpr 2749*4d6fc14bSjoergyear_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept 2750*4d6fc14bSjoerg{ return __lhs + (-__rhs); } 2751*4d6fc14bSjoerg 2752*4d6fc14bSjoerginline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } 2753*4d6fc14bSjoerginline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } 2754*4d6fc14bSjoerginline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } 2755*4d6fc14bSjoerginline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } 2756*4d6fc14bSjoerg 2757*4d6fc14bSjoerg 2758*4d6fc14bSjoergtemplate <class _Duration> 2759*4d6fc14bSjoergclass hh_mm_ss 2760*4d6fc14bSjoerg{ 2761*4d6fc14bSjoergprivate: 2762*4d6fc14bSjoerg static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration"); 2763*4d6fc14bSjoerg using __CommonType = common_type_t<_Duration, chrono::seconds>; 2764*4d6fc14bSjoerg 2765*4d6fc14bSjoerg static constexpr uint64_t __pow10(unsigned __exp) 2766*4d6fc14bSjoerg { 2767*4d6fc14bSjoerg uint64_t __ret = 1; 2768*4d6fc14bSjoerg for (unsigned __i = 0; __i < __exp; ++__i) 2769*4d6fc14bSjoerg __ret *= 10U; 2770*4d6fc14bSjoerg return __ret; 2771*4d6fc14bSjoerg } 2772*4d6fc14bSjoerg 2773*4d6fc14bSjoerg static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0) 2774*4d6fc14bSjoerg { 2775*4d6fc14bSjoerg if (__n >= 2 && __d != 0 && __w < 19) 2776*4d6fc14bSjoerg return 1 + __width(__n, __d % __n * 10, __w+1); 2777*4d6fc14bSjoerg return 0; 2778*4d6fc14bSjoerg } 2779*4d6fc14bSjoerg 2780*4d6fc14bSjoergpublic: 2781*4d6fc14bSjoerg static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ? 2782*4d6fc14bSjoerg __width(__CommonType::period::den) : 6u; 2783*4d6fc14bSjoerg using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>; 2784*4d6fc14bSjoerg 2785*4d6fc14bSjoerg constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {} 2786*4d6fc14bSjoerg 2787*4d6fc14bSjoerg constexpr explicit hh_mm_ss(_Duration __d) noexcept : 2788*4d6fc14bSjoerg __is_neg(__d < _Duration(0)), 2789*4d6fc14bSjoerg __h(duration_cast<chrono::hours> (abs(__d))), 2790*4d6fc14bSjoerg __m(duration_cast<chrono::minutes>(abs(__d) - hours())), 2791*4d6fc14bSjoerg __s(duration_cast<chrono::seconds>(abs(__d) - hours() - minutes())), 2792*4d6fc14bSjoerg __f(duration_cast<precision> (abs(__d) - hours() - minutes() - seconds())) 2793*4d6fc14bSjoerg {} 2794*4d6fc14bSjoerg 2795*4d6fc14bSjoerg constexpr bool is_negative() const noexcept { return __is_neg; } 2796*4d6fc14bSjoerg constexpr chrono::hours hours() const noexcept { return __h; } 2797*4d6fc14bSjoerg constexpr chrono::minutes minutes() const noexcept { return __m; } 2798*4d6fc14bSjoerg constexpr chrono::seconds seconds() const noexcept { return __s; } 2799*4d6fc14bSjoerg constexpr precision subseconds() const noexcept { return __f; } 2800*4d6fc14bSjoerg 2801*4d6fc14bSjoerg constexpr precision to_duration() const noexcept 2802*4d6fc14bSjoerg { 2803*4d6fc14bSjoerg auto __dur = __h + __m + __s + __f; 2804*4d6fc14bSjoerg return __is_neg ? -__dur : __dur; 2805*4d6fc14bSjoerg } 2806*4d6fc14bSjoerg 2807*4d6fc14bSjoerg constexpr explicit operator precision() const noexcept { return to_duration(); } 2808*4d6fc14bSjoerg 2809*4d6fc14bSjoergprivate: 2810*4d6fc14bSjoerg bool __is_neg; 2811*4d6fc14bSjoerg chrono::hours __h; 2812*4d6fc14bSjoerg chrono::minutes __m; 2813*4d6fc14bSjoerg chrono::seconds __s; 2814*4d6fc14bSjoerg precision __f; 2815*4d6fc14bSjoerg}; 2816*4d6fc14bSjoerg 2817*4d6fc14bSjoergconstexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); } 2818*4d6fc14bSjoergconstexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); } 2819*4d6fc14bSjoerg 2820*4d6fc14bSjoergconstexpr hours make12(const hours& __h) noexcept 2821*4d6fc14bSjoerg{ 2822*4d6fc14bSjoerg if (__h == hours( 0)) return hours(12); 2823*4d6fc14bSjoerg else if (__h <= hours(12)) return __h; 2824*4d6fc14bSjoerg else return __h - hours(12); 2825*4d6fc14bSjoerg} 2826*4d6fc14bSjoerg 2827*4d6fc14bSjoergconstexpr hours make24(const hours& __h, bool __is_pm) noexcept 2828*4d6fc14bSjoerg{ 2829*4d6fc14bSjoerg if (__is_pm) 2830*4d6fc14bSjoerg return __h == hours(12) ? __h : __h + hours(12); 2831*4d6fc14bSjoerg else 2832*4d6fc14bSjoerg return __h == hours(12) ? hours(0) : __h; 2833*4d6fc14bSjoerg} 2834*4d6fc14bSjoerg 2835*4d6fc14bSjoerg#endif // _LIBCPP_STD_VER > 17 2836*4d6fc14bSjoerg} // chrono 2837*4d6fc14bSjoerg 2838*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 11 2839*4d6fc14bSjoerg// Suffixes for duration literals [time.duration.literals] 2840*4d6fc14bSjoerginline namespace literals 2841*4d6fc14bSjoerg{ 2842*4d6fc14bSjoerg inline namespace chrono_literals 2843*4d6fc14bSjoerg { 2844*4d6fc14bSjoerg 2845*4d6fc14bSjoerg constexpr chrono::hours operator""h(unsigned long long __h) 2846*4d6fc14bSjoerg { 2847*4d6fc14bSjoerg return chrono::hours(static_cast<chrono::hours::rep>(__h)); 2848*4d6fc14bSjoerg } 2849*4d6fc14bSjoerg 2850*4d6fc14bSjoerg constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h) 2851*4d6fc14bSjoerg { 2852*4d6fc14bSjoerg return chrono::duration<long double, ratio<3600,1>>(__h); 2853*4d6fc14bSjoerg } 2854*4d6fc14bSjoerg 2855*4d6fc14bSjoerg 2856*4d6fc14bSjoerg constexpr chrono::minutes operator""min(unsigned long long __m) 2857*4d6fc14bSjoerg { 2858*4d6fc14bSjoerg return chrono::minutes(static_cast<chrono::minutes::rep>(__m)); 2859*4d6fc14bSjoerg } 2860*4d6fc14bSjoerg 2861*4d6fc14bSjoerg constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m) 2862*4d6fc14bSjoerg { 2863*4d6fc14bSjoerg return chrono::duration<long double, ratio<60,1>> (__m); 2864*4d6fc14bSjoerg } 2865*4d6fc14bSjoerg 2866*4d6fc14bSjoerg 2867*4d6fc14bSjoerg constexpr chrono::seconds operator""s(unsigned long long __s) 2868*4d6fc14bSjoerg { 2869*4d6fc14bSjoerg return chrono::seconds(static_cast<chrono::seconds::rep>(__s)); 2870*4d6fc14bSjoerg } 2871*4d6fc14bSjoerg 2872*4d6fc14bSjoerg constexpr chrono::duration<long double> operator""s(long double __s) 2873*4d6fc14bSjoerg { 2874*4d6fc14bSjoerg return chrono::duration<long double> (__s); 2875*4d6fc14bSjoerg } 2876*4d6fc14bSjoerg 2877*4d6fc14bSjoerg 2878*4d6fc14bSjoerg constexpr chrono::milliseconds operator""ms(unsigned long long __ms) 2879*4d6fc14bSjoerg { 2880*4d6fc14bSjoerg return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms)); 2881*4d6fc14bSjoerg } 2882*4d6fc14bSjoerg 2883*4d6fc14bSjoerg constexpr chrono::duration<long double, milli> operator""ms(long double __ms) 2884*4d6fc14bSjoerg { 2885*4d6fc14bSjoerg return chrono::duration<long double, milli>(__ms); 2886*4d6fc14bSjoerg } 2887*4d6fc14bSjoerg 2888*4d6fc14bSjoerg 2889*4d6fc14bSjoerg constexpr chrono::microseconds operator""us(unsigned long long __us) 2890*4d6fc14bSjoerg { 2891*4d6fc14bSjoerg return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us)); 2892*4d6fc14bSjoerg } 2893*4d6fc14bSjoerg 2894*4d6fc14bSjoerg constexpr chrono::duration<long double, micro> operator""us(long double __us) 2895*4d6fc14bSjoerg { 2896*4d6fc14bSjoerg return chrono::duration<long double, micro> (__us); 2897*4d6fc14bSjoerg } 2898*4d6fc14bSjoerg 2899*4d6fc14bSjoerg 2900*4d6fc14bSjoerg constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) 2901*4d6fc14bSjoerg { 2902*4d6fc14bSjoerg return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns)); 2903*4d6fc14bSjoerg } 2904*4d6fc14bSjoerg 2905*4d6fc14bSjoerg constexpr chrono::duration<long double, nano> operator""ns(long double __ns) 2906*4d6fc14bSjoerg { 2907*4d6fc14bSjoerg return chrono::duration<long double, nano> (__ns); 2908*4d6fc14bSjoerg } 2909*4d6fc14bSjoerg 2910*4d6fc14bSjoerg#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS) 2911*4d6fc14bSjoerg constexpr chrono::day operator ""d(unsigned long long __d) noexcept 2912*4d6fc14bSjoerg { 2913*4d6fc14bSjoerg return chrono::day(static_cast<unsigned>(__d)); 2914*4d6fc14bSjoerg } 2915*4d6fc14bSjoerg 2916*4d6fc14bSjoerg constexpr chrono::year operator ""y(unsigned long long __y) noexcept 2917*4d6fc14bSjoerg { 2918*4d6fc14bSjoerg return chrono::year(static_cast<int>(__y)); 2919*4d6fc14bSjoerg } 2920*4d6fc14bSjoerg#endif 2921*4d6fc14bSjoerg}} 2922*4d6fc14bSjoerg 2923*4d6fc14bSjoergnamespace chrono { // hoist the literals into namespace std::chrono 2924*4d6fc14bSjoerg using namespace literals::chrono_literals; 2925*4d6fc14bSjoerg} 2926*4d6fc14bSjoerg 2927*4d6fc14bSjoerg#endif 2928*4d6fc14bSjoerg 2929*4d6fc14bSjoerg_LIBCPP_END_NAMESPACE_STD 2930*4d6fc14bSjoerg 2931*4d6fc14bSjoerg#ifndef _LIBCPP_CXX03_LANG 2932*4d6fc14bSjoerg_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM 2933*4d6fc14bSjoergstruct _FilesystemClock { 2934*4d6fc14bSjoerg#if !defined(_LIBCPP_HAS_NO_INT128) 2935*4d6fc14bSjoerg typedef __int128_t rep; 2936*4d6fc14bSjoerg typedef nano period; 2937*4d6fc14bSjoerg#else 2938*4d6fc14bSjoerg typedef long long rep; 2939*4d6fc14bSjoerg typedef nano period; 2940*4d6fc14bSjoerg#endif 2941*4d6fc14bSjoerg 2942*4d6fc14bSjoerg typedef chrono::duration<rep, period> duration; 2943*4d6fc14bSjoerg typedef chrono::time_point<_FilesystemClock> time_point; 2944*4d6fc14bSjoerg 2945*4d6fc14bSjoerg _LIBCPP_EXPORTED_FROM_ABI 2946*4d6fc14bSjoerg static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; 2947*4d6fc14bSjoerg 2948*4d6fc14bSjoerg _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept; 2949*4d6fc14bSjoerg 2950*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 2951*4d6fc14bSjoerg static time_t to_time_t(const time_point& __t) noexcept { 2952*4d6fc14bSjoerg typedef chrono::duration<rep> __secs; 2953*4d6fc14bSjoerg return time_t( 2954*4d6fc14bSjoerg chrono::duration_cast<__secs>(__t.time_since_epoch()).count()); 2955*4d6fc14bSjoerg } 2956*4d6fc14bSjoerg 2957*4d6fc14bSjoerg _LIBCPP_INLINE_VISIBILITY 2958*4d6fc14bSjoerg static time_point from_time_t(time_t __t) noexcept { 2959*4d6fc14bSjoerg typedef chrono::duration<rep> __secs; 2960*4d6fc14bSjoerg return time_point(__secs(__t)); 2961*4d6fc14bSjoerg } 2962*4d6fc14bSjoerg}; 2963*4d6fc14bSjoerg_LIBCPP_END_NAMESPACE_FILESYSTEM 2964*4d6fc14bSjoerg#endif // !_LIBCPP_CXX03_LANG 2965*4d6fc14bSjoerg 2966*4d6fc14bSjoerg_LIBCPP_POP_MACROS 2967*4d6fc14bSjoerg 2968*4d6fc14bSjoerg#endif // _LIBCPP_CHRONO 2969