xref: /freebsd-12.1/contrib/libc++/include/chrono (revision b5893f02)
17a984708SDavid Chisnall// -*- C++ -*-
27a984708SDavid Chisnall//===---------------------------- chrono ----------------------------------===//
37a984708SDavid Chisnall//
47a984708SDavid Chisnall//                     The LLVM Compiler Infrastructure
57a984708SDavid Chisnall//
67a984708SDavid Chisnall// This file is dual licensed under the MIT and the University of Illinois Open
77a984708SDavid Chisnall// Source Licenses. See LICENSE.TXT for details.
87a984708SDavid Chisnall//
97a984708SDavid Chisnall//===----------------------------------------------------------------------===//
107a984708SDavid Chisnall
117a984708SDavid Chisnall#ifndef _LIBCPP_CHRONO
127a984708SDavid Chisnall#define _LIBCPP_CHRONO
137a984708SDavid Chisnall
147a984708SDavid Chisnall/*
157a984708SDavid Chisnall    chrono synopsis
167a984708SDavid Chisnall
177a984708SDavid Chisnallnamespace std
187a984708SDavid Chisnall{
197a984708SDavid Chisnallnamespace chrono
207a984708SDavid Chisnall{
217a984708SDavid Chisnall
227a984708SDavid Chisnalltemplate <class ToDuration, class Rep, class Period>
23936e9439SDimitry Andricconstexpr
247a984708SDavid ChisnallToDuration
257a984708SDavid Chisnallduration_cast(const duration<Rep, Period>& fd);
267a984708SDavid Chisnall
277a984708SDavid Chisnalltemplate <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
287a984708SDavid Chisnall
2930785c0eSDimitry Andrictemplate <class Rep> inline constexpr bool treat_as_floating_point_v
309729cf09SDimitry Andric    = treat_as_floating_point<Rep>::value;                       // C++17
319729cf09SDimitry Andric
327a984708SDavid Chisnalltemplate <class Rep>
337a984708SDavid Chisnallstruct duration_values
347a984708SDavid Chisnall{
357a984708SDavid Chisnallpublic:
36*b5893f02SDimitry Andric    static constexpr Rep zero(); // noexcept in C++20
37*b5893f02SDimitry Andric    static constexpr Rep max();  // noexcept in C++20
38*b5893f02SDimitry Andric    static constexpr Rep min();  // noexcept in C++20
397a984708SDavid Chisnall};
407a984708SDavid Chisnall
417a984708SDavid Chisnall// duration
427a984708SDavid Chisnall
437a984708SDavid Chisnalltemplate <class Rep, class Period = ratio<1>>
447a984708SDavid Chisnallclass duration
457a984708SDavid Chisnall{
467a984708SDavid Chisnall    static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
477a984708SDavid Chisnall    static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
487a984708SDavid Chisnall    static_assert(Period::num > 0, "duration period must be positive");
497a984708SDavid Chisnallpublic:
507a984708SDavid Chisnall    typedef Rep rep;
51540d2a8bSDimitry Andric    typedef typename _Period::type period;
527a984708SDavid Chisnall
53936e9439SDimitry Andric    constexpr duration() = default;
547a984708SDavid Chisnall    template <class Rep2>
55936e9439SDimitry Andric        constexpr explicit duration(const Rep2& r,
567a984708SDavid Chisnall            typename enable_if
577a984708SDavid Chisnall            <
587a984708SDavid Chisnall               is_convertible<Rep2, rep>::value &&
597a984708SDavid Chisnall               (treat_as_floating_point<rep>::value ||
607a984708SDavid Chisnall               !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
617a984708SDavid Chisnall            >::type* = 0);
627a984708SDavid Chisnall
637a984708SDavid Chisnall    // conversions
647a984708SDavid Chisnall    template <class Rep2, class Period2>
65936e9439SDimitry Andric        constexpr duration(const duration<Rep2, Period2>& d,
667a984708SDavid Chisnall            typename enable_if
677a984708SDavid Chisnall            <
687a984708SDavid Chisnall                treat_as_floating_point<rep>::value ||
697a984708SDavid Chisnall                ratio_divide<Period2, period>::type::den == 1
707a984708SDavid Chisnall            >::type* = 0);
717a984708SDavid Chisnall
727a984708SDavid Chisnall    // observer
737a984708SDavid Chisnall
74936e9439SDimitry Andric    constexpr rep count() const;
757a984708SDavid Chisnall
767a984708SDavid Chisnall    // arithmetic
777a984708SDavid Chisnall
78540d2a8bSDimitry Andric    constexpr common_type<duration>::type  operator+() const;
79540d2a8bSDimitry Andric    constexpr common_type<duration>::type  operator-() const;
80*b5893f02SDimitry Andric    constexpr duration& operator++();    // constexpr in C++17
81*b5893f02SDimitry Andric    constexpr duration  operator++(int); // constexpr in C++17
82*b5893f02SDimitry Andric    constexpr duration& operator--();    // constexpr in C++17
83*b5893f02SDimitry Andric    constexpr duration  operator--(int); // constexpr in C++17
847a984708SDavid Chisnall
85*b5893f02SDimitry Andric    constexpr duration& operator+=(const duration& d);  // constexpr in C++17
86*b5893f02SDimitry Andric    constexpr duration& operator-=(const duration& d);  // constexpr in C++17
877a984708SDavid Chisnall
88*b5893f02SDimitry Andric    duration& operator*=(const rep& rhs);       // constexpr in C++17
89*b5893f02SDimitry Andric    duration& operator/=(const rep& rhs);       // constexpr in C++17
90*b5893f02SDimitry Andric    duration& operator%=(const rep& rhs);       // constexpr in C++17
91*b5893f02SDimitry Andric    duration& operator%=(const duration& rhs);  // constexpr in C++17
927a984708SDavid Chisnall
937a984708SDavid Chisnall    // special values
947a984708SDavid Chisnall
95*b5893f02SDimitry Andric    static constexpr duration zero(); // noexcept in C++20
96*b5893f02SDimitry Andric    static constexpr duration min();  // noexcept in C++20
97*b5893f02SDimitry Andric    static constexpr duration max();  // noexcept in C++20
987a984708SDavid Chisnall};
997a984708SDavid Chisnall
1007a984708SDavid Chisnalltypedef duration<long long,         nano> nanoseconds;
1017a984708SDavid Chisnalltypedef duration<long long,        micro> microseconds;
1027a984708SDavid Chisnalltypedef duration<long long,        milli> milliseconds;
1037a984708SDavid Chisnalltypedef duration<long long              > seconds;
1047a984708SDavid Chisnalltypedef duration<     long, ratio<  60> > minutes;
1057a984708SDavid Chisnalltypedef duration<     long, ratio<3600> > hours;
1067a984708SDavid Chisnall
1077a984708SDavid Chisnalltemplate <class Clock, class Duration = typename Clock::duration>
1087a984708SDavid Chisnallclass time_point
1097a984708SDavid Chisnall{
1107a984708SDavid Chisnallpublic:
1117a984708SDavid Chisnall    typedef Clock                     clock;
1127a984708SDavid Chisnall    typedef Duration                  duration;
1137a984708SDavid Chisnall    typedef typename duration::rep    rep;
1147a984708SDavid Chisnall    typedef typename duration::period period;
1157a984708SDavid Chisnallprivate:
1167a984708SDavid Chisnall    duration d_;  // exposition only
1177a984708SDavid Chisnall
1187a984708SDavid Chisnallpublic:
1194f7ab58eSDimitry Andric    time_point();  // has value "epoch" // constexpr in C++14
1204f7ab58eSDimitry Andric    explicit time_point(const duration& d);  // same as time_point() + d // constexpr in C++14
1217a984708SDavid Chisnall
1227a984708SDavid Chisnall    // conversions
1237a984708SDavid Chisnall    template <class Duration2>
1244f7ab58eSDimitry Andric       time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
1257a984708SDavid Chisnall
1267a984708SDavid Chisnall    // observer
1277a984708SDavid Chisnall
1284f7ab58eSDimitry Andric    duration time_since_epoch() const; // constexpr in C++14
1297a984708SDavid Chisnall
1307a984708SDavid Chisnall    // arithmetic
1317a984708SDavid Chisnall
132*b5893f02SDimitry Andric    time_point& operator+=(const duration& d); // constexpr in C++17
133*b5893f02SDimitry Andric    time_point& operator-=(const duration& d); // constexpr in C++17
1347a984708SDavid Chisnall
1357a984708SDavid Chisnall    // special values
1367a984708SDavid Chisnall
137*b5893f02SDimitry Andric    static constexpr time_point min();  // noexcept in C++20
138*b5893f02SDimitry Andric    static constexpr time_point max();  // noexcept in C++20
1397a984708SDavid Chisnall};
1407a984708SDavid Chisnall
1417a984708SDavid Chisnall} // chrono
1427a984708SDavid Chisnall
1437a984708SDavid Chisnall// common_type traits
1447a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
1457a984708SDavid Chisnall  struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
1467a984708SDavid Chisnall
1477a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Duration2>
1487a984708SDavid Chisnall  struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
1497a984708SDavid Chisnall
1507a984708SDavid Chisnallnamespace chrono {
1517a984708SDavid Chisnall
1524ba319b5SDimitry Andric
1534ba319b5SDimitry Andrictemplate<class T> struct is_clock;  // C++20
1544ba319b5SDimitry Andrictemplate<class T> inline constexpr bool is_clock_v = is_clock<T>::value;   // C++20
1554ba319b5SDimitry Andric
1564ba319b5SDimitry Andric
1577a984708SDavid Chisnall// duration arithmetic
1587a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
159936e9439SDimitry Andric  constexpr
1607a984708SDavid Chisnall  typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
1617a984708SDavid Chisnall  operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
1627a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
163936e9439SDimitry Andric  constexpr
1647a984708SDavid Chisnall  typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
1657a984708SDavid Chisnall  operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
1667a984708SDavid Chisnalltemplate <class Rep1, class Period, class Rep2>
167936e9439SDimitry Andric  constexpr
1687a984708SDavid Chisnall  duration<typename common_type<Rep1, Rep2>::type, Period>
1697a984708SDavid Chisnall  operator*(const duration<Rep1, Period>& d, const Rep2& s);
1707a984708SDavid Chisnalltemplate <class Rep1, class Period, class Rep2>
171936e9439SDimitry Andric  constexpr
1727a984708SDavid Chisnall  duration<typename common_type<Rep1, Rep2>::type, Period>
1737a984708SDavid Chisnall  operator*(const Rep1& s, const duration<Rep2, Period>& d);
1747a984708SDavid Chisnalltemplate <class Rep1, class Period, class Rep2>
175936e9439SDimitry Andric  constexpr
1767a984708SDavid Chisnall  duration<typename common_type<Rep1, Rep2>::type, Period>
1777a984708SDavid Chisnall  operator/(const duration<Rep1, Period>& d, const Rep2& s);
1787a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
179936e9439SDimitry Andric  constexpr
1807a984708SDavid Chisnall  typename common_type<Rep1, Rep2>::type
1817a984708SDavid Chisnall  operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
1827a984708SDavid Chisnall
1837a984708SDavid Chisnall// duration comparisons
1847a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
185936e9439SDimitry Andric   constexpr
1867a984708SDavid Chisnall   bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
1877a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
188936e9439SDimitry Andric   constexpr
1897a984708SDavid Chisnall   bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
1907a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
191936e9439SDimitry Andric   constexpr
1927a984708SDavid Chisnall   bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
1937a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
194936e9439SDimitry Andric   constexpr
1957a984708SDavid Chisnall   bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
1967a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
197936e9439SDimitry Andric   constexpr
1987a984708SDavid Chisnall   bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
1997a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Rep2, class Period2>
200936e9439SDimitry Andric   constexpr
2017a984708SDavid Chisnall   bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
2027a984708SDavid Chisnall
2037a984708SDavid Chisnall// duration_cast
2047a984708SDavid Chisnalltemplate <class ToDuration, class Rep, class Period>
2057a984708SDavid Chisnall  ToDuration duration_cast(const duration<Rep, Period>& d);
2067a984708SDavid Chisnall
2079729cf09SDimitry Andrictemplate <class ToDuration, class Rep, class Period>
2089729cf09SDimitry Andric    constexpr ToDuration floor(const duration<Rep, Period>& d);    // C++17
2099729cf09SDimitry Andrictemplate <class ToDuration, class Rep, class Period>
2109729cf09SDimitry Andric    constexpr ToDuration ceil(const duration<Rep, Period>& d);     // C++17
2119729cf09SDimitry Andrictemplate <class ToDuration, class Rep, class Period>
2129729cf09SDimitry Andric    constexpr ToDuration round(const duration<Rep, Period>& d);    // C++17
2139729cf09SDimitry Andric
2144ba319b5SDimitry Andric// duration I/O is elsewhere
2154ba319b5SDimitry Andric
2164f7ab58eSDimitry Andric// time_point arithmetic (all constexpr in C++14)
2177a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Rep2, class Period2>
2187a984708SDavid Chisnall  time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
2197a984708SDavid Chisnall  operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
2207a984708SDavid Chisnalltemplate <class Rep1, class Period1, class Clock, class Duration2>
2217a984708SDavid Chisnall  time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
2227a984708SDavid Chisnall  operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
2237a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Rep2, class Period2>
2247a984708SDavid Chisnall  time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
2257a984708SDavid Chisnall  operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
2267a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Duration2>
2277a984708SDavid Chisnall  typename common_type<Duration1, Duration2>::type
2287a984708SDavid Chisnall  operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
2297a984708SDavid Chisnall
2304f7ab58eSDimitry Andric// time_point comparisons (all constexpr in C++14)
2317a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Duration2>
2327a984708SDavid Chisnall   bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
2337a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Duration2>
2347a984708SDavid Chisnall   bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
2357a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Duration2>
2367a984708SDavid Chisnall   bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
2377a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Duration2>
2387a984708SDavid Chisnall   bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
2397a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Duration2>
2407a984708SDavid Chisnall   bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
2417a984708SDavid Chisnalltemplate <class Clock, class Duration1, class Duration2>
2427a984708SDavid Chisnall   bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
2437a984708SDavid Chisnall
2444f7ab58eSDimitry Andric// time_point_cast (constexpr in C++14)
2457a984708SDavid Chisnall
2467a984708SDavid Chisnalltemplate <class ToDuration, class Clock, class Duration>
2477a984708SDavid Chisnall  time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
2487a984708SDavid Chisnall
2499729cf09SDimitry Andrictemplate <class ToDuration, class Clock, class Duration>
2509729cf09SDimitry Andric    constexpr time_point<Clock, ToDuration>
2519729cf09SDimitry Andric    floor(const time_point<Clock, Duration>& tp);                  // C++17
2529729cf09SDimitry Andric
2539729cf09SDimitry Andrictemplate <class ToDuration, class Clock, class Duration>
2549729cf09SDimitry Andric    constexpr time_point<Clock, ToDuration>
2559729cf09SDimitry Andric    ceil(const time_point<Clock, Duration>& tp);                   // C++17
2569729cf09SDimitry Andric
2579729cf09SDimitry Andrictemplate <class ToDuration, class Clock, class Duration>
2589729cf09SDimitry Andric    constexpr time_point<Clock, ToDuration>
2599729cf09SDimitry Andric    round(const time_point<Clock, Duration>& tp);                  // C++17
2609729cf09SDimitry Andric
2619729cf09SDimitry Andrictemplate <class Rep, class Period>
2629729cf09SDimitry Andric    constexpr duration<Rep, Period> abs(duration<Rep, Period> d);  // C++17
2634ba319b5SDimitry Andric
2647a984708SDavid Chisnall// Clocks
2657a984708SDavid Chisnall
2667a984708SDavid Chisnallclass system_clock
2677a984708SDavid Chisnall{
2687a984708SDavid Chisnallpublic:
2697a984708SDavid Chisnall    typedef microseconds                     duration;
2707a984708SDavid Chisnall    typedef duration::rep                    rep;
2717a984708SDavid Chisnall    typedef duration::period                 period;
2727a984708SDavid Chisnall    typedef chrono::time_point<system_clock> time_point;
2734f7ab58eSDimitry Andric    static const bool is_steady =            false; // constexpr in C++14
2747a984708SDavid Chisnall
2757a984708SDavid Chisnall    static time_point now() noexcept;
2767a984708SDavid Chisnall    static time_t     to_time_t  (const time_point& __t) noexcept;
2777a984708SDavid Chisnall    static time_point from_time_t(time_t __t) noexcept;
2787a984708SDavid Chisnall};
2797a984708SDavid Chisnall
2804ba319b5SDimitry Andrictemplate <class Duration>
2814ba319b5SDimitry Andric  using sys_time  = time_point<system_clock, Duration>; // C++20
2824ba319b5SDimitry Andricusing sys_seconds = sys_time<seconds>;                  // C++20
2834ba319b5SDimitry Andricusing sys_days    = sys_time<days>;                     // C++20
2844ba319b5SDimitry Andric
2854ba319b5SDimitry Andricclass utc_clock;                                        // C++20
2864ba319b5SDimitry Andric
2874ba319b5SDimitry Andrictemplate <class Duration>
2884ba319b5SDimitry Andric  using utc_time  = time_point<utc_clock, Duration>;    // C++20
2894ba319b5SDimitry Andricusing utc_seconds = utc_time<seconds>;                  // C++20
2904ba319b5SDimitry Andric
2914ba319b5SDimitry Andricclass tai_clock;                                        // C++20
2924ba319b5SDimitry Andric
2934ba319b5SDimitry Andrictemplate <class Duration>
2944ba319b5SDimitry Andric  using tai_time  = time_point<tai_clock, Duration>;    // C++20
2954ba319b5SDimitry Andricusing tai_seconds = tai_time<seconds>;                  // C++20
2964ba319b5SDimitry Andric
2974ba319b5SDimitry Andricclass file_clock;                                       // C++20
2984ba319b5SDimitry Andric
2994ba319b5SDimitry Andrictemplate<class Duration>
3004ba319b5SDimitry Andric  using file_time = time_point<file_clock, Duration>;   // C++20
3014ba319b5SDimitry Andric
3027a984708SDavid Chisnallclass steady_clock
3037a984708SDavid Chisnall{
3047a984708SDavid Chisnallpublic:
3057a984708SDavid Chisnall    typedef nanoseconds                                   duration;
3067a984708SDavid Chisnall    typedef duration::rep                                 rep;
3077a984708SDavid Chisnall    typedef duration::period                              period;
3087a984708SDavid Chisnall    typedef chrono::time_point<steady_clock, duration>    time_point;
3094f7ab58eSDimitry Andric    static const bool is_steady =                         true; // constexpr in C++14
3107a984708SDavid Chisnall
3117a984708SDavid Chisnall    static time_point now() noexcept;
3127a984708SDavid Chisnall};
3137a984708SDavid Chisnall
3147a984708SDavid Chisnalltypedef steady_clock high_resolution_clock;
3157a984708SDavid Chisnall
3164ba319b5SDimitry Andric// 25.7.8, local time           // C++20
3174ba319b5SDimitry Andricstruct local_t {};
3184ba319b5SDimitry Andrictemplate<class Duration>
3194ba319b5SDimitry Andric  using local_time  = time_point<local_t, Duration>;
3204ba319b5SDimitry Andricusing local_seconds = local_time<seconds>;
3214ba319b5SDimitry Andricusing local_days    = local_time<days>;
3224ba319b5SDimitry Andric
3234ba319b5SDimitry Andric// 25.7.9, time_point conversions template<class DestClock, class SourceClock>    // C++20
3244ba319b5SDimitry Andricstruct clock_time_conversion;
3254ba319b5SDimitry Andric
3264ba319b5SDimitry Andrictemplate<class DestClock, class SourceClock, class Duration>
3274ba319b5SDimitry Andric  auto clock_cast(const time_point<SourceClock, Duration>& t);
3284ba319b5SDimitry Andric
3294ba319b5SDimitry Andric// 25.8.2, class last_spec    // C++20
3304ba319b5SDimitry Andricstruct last_spec;
3314ba319b5SDimitry Andric
3324ba319b5SDimitry Andric// 25.8.3, class day          // C++20
3334ba319b5SDimitry Andric
3344ba319b5SDimitry Andricclass day;
3354ba319b5SDimitry Andricconstexpr bool operator==(const day& x, const day& y) noexcept;
3364ba319b5SDimitry Andricconstexpr bool operator!=(const day& x, const day& y) noexcept;
3374ba319b5SDimitry Andricconstexpr bool operator< (const day& x, const day& y) noexcept;
3384ba319b5SDimitry Andricconstexpr bool operator> (const day& x, const day& y) noexcept;
3394ba319b5SDimitry Andricconstexpr bool operator<=(const day& x, const day& y) noexcept;
3404ba319b5SDimitry Andricconstexpr bool operator>=(const day& x, const day& y) noexcept;
3414ba319b5SDimitry Andricconstexpr day  operator+(const day&  x, const days& y) noexcept;
3424ba319b5SDimitry Andricconstexpr day  operator+(const days& x, const day&  y) noexcept;
3434ba319b5SDimitry Andricconstexpr day  operator-(const day&  x, const days& y) noexcept;
3444ba319b5SDimitry Andricconstexpr days operator-(const day&  x, const day&  y) noexcept;
3454ba319b5SDimitry Andric
3464ba319b5SDimitry Andric// 25.8.4, class month    // C++20
3474ba319b5SDimitry Andricclass month;
3484ba319b5SDimitry Andricconstexpr bool operator==(const month& x, const month& y) noexcept;
3494ba319b5SDimitry Andricconstexpr bool operator!=(const month& x, const month& y) noexcept;
3504ba319b5SDimitry Andricconstexpr bool operator< (const month& x, const month& y) noexcept;
3514ba319b5SDimitry Andricconstexpr bool operator> (const month& x, const month& y) noexcept;
3524ba319b5SDimitry Andricconstexpr bool operator<=(const month& x, const month& y) noexcept;
3534ba319b5SDimitry Andricconstexpr bool operator>=(const month& x, const month& y) noexcept;
3544ba319b5SDimitry Andricconstexpr month  operator+(const month&  x, const months& y) noexcept;
3554ba319b5SDimitry Andricconstexpr month  operator+(const months& x,  const month& y) noexcept;
3564ba319b5SDimitry Andricconstexpr month  operator-(const month&  x, const months& y) noexcept;
3574ba319b5SDimitry Andricconstexpr months operator-(const month&  x,  const month& y) noexcept;
3584ba319b5SDimitry Andric
3594ba319b5SDimitry Andric// 25.8.5, class year    // C++20
3604ba319b5SDimitry Andricclass year;
3614ba319b5SDimitry Andricconstexpr bool operator==(const year& x, const year& y) noexcept;
3624ba319b5SDimitry Andricconstexpr bool operator!=(const year& x, const year& y) noexcept;
3634ba319b5SDimitry Andricconstexpr bool operator< (const year& x, const year& y) noexcept;
3644ba319b5SDimitry Andricconstexpr bool operator> (const year& x, const year& y) noexcept;
3654ba319b5SDimitry Andricconstexpr bool operator<=(const year& x, const year& y) noexcept;
3664ba319b5SDimitry Andricconstexpr bool operator>=(const year& x, const year& y) noexcept;
3674ba319b5SDimitry Andricconstexpr year  operator+(const year&  x, const years& y) noexcept;
3684ba319b5SDimitry Andricconstexpr year  operator+(const years& x, const year&  y) noexcept;
3694ba319b5SDimitry Andricconstexpr year  operator-(const year&  x, const years& y) noexcept;
3704ba319b5SDimitry Andricconstexpr years operator-(const year&  x, const year&  y) noexcept;
3714ba319b5SDimitry Andric
3724ba319b5SDimitry Andric// 25.8.6, class weekday    // C++20
3734ba319b5SDimitry Andricclass weekday;
3744ba319b5SDimitry Andric
3754ba319b5SDimitry Andricconstexpr bool operator==(const weekday& x, const weekday& y) noexcept;
3764ba319b5SDimitry Andricconstexpr bool operator!=(const weekday& x, const weekday& y) noexcept;
3774ba319b5SDimitry Andricconstexpr weekday operator+(const weekday& x, const days&    y) noexcept;
3784ba319b5SDimitry Andricconstexpr weekday operator+(const days&    x, const weekday& y) noexcept;
3794ba319b5SDimitry Andricconstexpr weekday operator-(const weekday& x, const days&    y) noexcept;
3804ba319b5SDimitry Andricconstexpr days    operator-(const weekday& x, const weekday& y) noexcept;
3814ba319b5SDimitry Andric
3824ba319b5SDimitry Andric// 25.8.7, class weekday_indexed    // C++20
3834ba319b5SDimitry Andric
3844ba319b5SDimitry Andricclass weekday_indexed;
3854ba319b5SDimitry Andricconstexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
3864ba319b5SDimitry Andricconstexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept;
3874ba319b5SDimitry Andric
3884ba319b5SDimitry Andric// 25.8.8, class weekday_last    // C++20
3894ba319b5SDimitry Andricclass weekday_last;
3904ba319b5SDimitry Andric
3914ba319b5SDimitry Andricconstexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept;
3924ba319b5SDimitry Andricconstexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept;
3934ba319b5SDimitry Andric
3944ba319b5SDimitry Andric// 25.8.9, class month_day    // C++20
3954ba319b5SDimitry Andricclass month_day;
3964ba319b5SDimitry Andric
3974ba319b5SDimitry Andricconstexpr bool operator==(const month_day& x, const month_day& y) noexcept;
3984ba319b5SDimitry Andricconstexpr bool operator!=(const month_day& x, const month_day& y) noexcept;
3994ba319b5SDimitry Andricconstexpr bool operator< (const month_day& x, const month_day& y) noexcept;
4004ba319b5SDimitry Andricconstexpr bool operator> (const month_day& x, const month_day& y) noexcept;
4014ba319b5SDimitry Andricconstexpr bool operator<=(const month_day& x, const month_day& y) noexcept;
4024ba319b5SDimitry Andricconstexpr bool operator>=(const month_day& x, const month_day& y) noexcept;
4034ba319b5SDimitry Andric
4044ba319b5SDimitry Andric
4054ba319b5SDimitry Andric// 25.8.10, class month_day_last    // C++20
4064ba319b5SDimitry Andricclass month_day_last;
4074ba319b5SDimitry Andric
4084ba319b5SDimitry Andricconstexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
4094ba319b5SDimitry Andricconstexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept;
4104ba319b5SDimitry Andricconstexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept;
4114ba319b5SDimitry Andricconstexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept;
4124ba319b5SDimitry Andricconstexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept;
4134ba319b5SDimitry Andricconstexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept;
4144ba319b5SDimitry Andric
4154ba319b5SDimitry Andric// 25.8.11, class month_weekday    // C++20
4164ba319b5SDimitry Andricclass month_weekday;
4174ba319b5SDimitry Andric
4184ba319b5SDimitry Andricconstexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
4194ba319b5SDimitry Andricconstexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept;
4204ba319b5SDimitry Andric
4214ba319b5SDimitry Andric// 25.8.12, class month_weekday_last    // C++20
4224ba319b5SDimitry Andricclass month_weekday_last;
4234ba319b5SDimitry Andric
4244ba319b5SDimitry Andricconstexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
4254ba319b5SDimitry Andricconstexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept;
4264ba319b5SDimitry Andric
4274ba319b5SDimitry Andric
4284ba319b5SDimitry Andric// 25.8.13, class year_month    // C++20
4294ba319b5SDimitry Andricclass year_month;
4304ba319b5SDimitry Andric
4314ba319b5SDimitry Andricconstexpr bool operator==(const year_month& x, const year_month& y) noexcept;
4324ba319b5SDimitry Andricconstexpr bool operator!=(const year_month& x, const year_month& y) noexcept;
4334ba319b5SDimitry Andricconstexpr bool operator< (const year_month& x, const year_month& y) noexcept;
4344ba319b5SDimitry Andricconstexpr bool operator> (const year_month& x, const year_month& y) noexcept;
4354ba319b5SDimitry Andricconstexpr bool operator<=(const year_month& x, const year_month& y) noexcept;
4364ba319b5SDimitry Andricconstexpr bool operator>=(const year_month& x, const year_month& y) noexcept;
4374ba319b5SDimitry Andric
4384ba319b5SDimitry Andricconstexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
4394ba319b5SDimitry Andricconstexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
4404ba319b5SDimitry Andricconstexpr year_month operator-(const year_month& ym, const months& dm) noexcept;
4414ba319b5SDimitry Andricconstexpr months operator-(const year_month& x, const year_month& y) noexcept;
4424ba319b5SDimitry Andricconstexpr year_month operator+(const year_month& ym, const years& dy) noexcept;
4434ba319b5SDimitry Andricconstexpr year_month operator+(const years& dy, const year_month& ym) noexcept;
4444ba319b5SDimitry Andricconstexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
4454ba319b5SDimitry Andric
4464ba319b5SDimitry Andric// 25.8.14, class year_month_day class    // C++20
4474ba319b5SDimitry Andricyear_month_day;
4484ba319b5SDimitry Andric
4494ba319b5SDimitry Andricconstexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
4504ba319b5SDimitry Andricconstexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept;
4514ba319b5SDimitry Andricconstexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept;
4524ba319b5SDimitry Andricconstexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept;
4534ba319b5SDimitry Andricconstexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept;
4544ba319b5SDimitry Andricconstexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept;
4554ba319b5SDimitry Andric
4564ba319b5SDimitry Andricconstexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
4574ba319b5SDimitry Andricconstexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
4584ba319b5SDimitry Andricconstexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
4594ba319b5SDimitry Andricconstexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
4604ba319b5SDimitry Andricconstexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
4614ba319b5SDimitry Andricconstexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
4624ba319b5SDimitry Andric
4634ba319b5SDimitry Andric
4644ba319b5SDimitry Andric// 25.8.15, class year_month_day_last    // C++20
4654ba319b5SDimitry Andricclass year_month_day_last;
4664ba319b5SDimitry Andric
4674ba319b5SDimitry Andricconstexpr bool operator==(const year_month_day_last& x,
4684ba319b5SDimitry Andric                          const year_month_day_last& y) noexcept;
4694ba319b5SDimitry Andricconstexpr bool operator!=(const year_month_day_last& x,
4704ba319b5SDimitry Andric                          const year_month_day_last& y) noexcept;
4714ba319b5SDimitry Andricconstexpr bool operator< (const year_month_day_last& x,
4724ba319b5SDimitry Andric                          const year_month_day_last& y) noexcept;
4734ba319b5SDimitry Andricconstexpr bool operator> (const year_month_day_last& x,
4744ba319b5SDimitry Andric                          const year_month_day_last& y) noexcept;
4754ba319b5SDimitry Andricconstexpr bool operator<=(const year_month_day_last& x,
4764ba319b5SDimitry Andric                          const year_month_day_last& y) noexcept;
4774ba319b5SDimitry Andricconstexpr bool operator>=(const year_month_day_last& x,
4784ba319b5SDimitry Andric                          const year_month_day_last& y) noexcept;
4794ba319b5SDimitry Andric
4804ba319b5SDimitry Andricconstexpr year_month_day_last
4814ba319b5SDimitry Andric  operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
4824ba319b5SDimitry Andricconstexpr year_month_day_last
4834ba319b5SDimitry Andric  operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
4844ba319b5SDimitry Andricconstexpr year_month_day_last
4854ba319b5SDimitry Andric  operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
4864ba319b5SDimitry Andricconstexpr year_month_day_last
4874ba319b5SDimitry Andric  operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
4884ba319b5SDimitry Andricconstexpr year_month_day_last
4894ba319b5SDimitry Andric  operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
4904ba319b5SDimitry Andricconstexpr year_month_day_last
4914ba319b5SDimitry Andric  operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
4924ba319b5SDimitry Andric
4934ba319b5SDimitry Andric// 25.8.16, class year_month_weekday    // C++20
4944ba319b5SDimitry Andricclass year_month_weekday;
4954ba319b5SDimitry Andric
4964ba319b5SDimitry Andricconstexpr bool operator==(const year_month_weekday& x,
4974ba319b5SDimitry Andric                          const year_month_weekday& y) noexcept;
4984ba319b5SDimitry Andricconstexpr bool operator!=(const year_month_weekday& x,
4994ba319b5SDimitry Andric                          const year_month_weekday& y) noexcept;
5004ba319b5SDimitry Andric
5014ba319b5SDimitry Andricconstexpr year_month_weekday
5024ba319b5SDimitry Andric  operator+(const year_month_weekday& ymwd, const months& dm) noexcept;
5034ba319b5SDimitry Andricconstexpr year_month_weekday
5044ba319b5SDimitry Andric  operator+(const months& dm, const year_month_weekday& ymwd) noexcept;
5054ba319b5SDimitry Andricconstexpr year_month_weekday
5064ba319b5SDimitry Andric  operator+(const year_month_weekday& ymwd, const years& dy) noexcept;
5074ba319b5SDimitry Andricconstexpr year_month_weekday
5084ba319b5SDimitry Andric  operator+(const years& dy, const year_month_weekday& ymwd) noexcept;
5094ba319b5SDimitry Andricconstexpr year_month_weekday
5104ba319b5SDimitry Andric  operator-(const year_month_weekday& ymwd, const months& dm) noexcept;
5114ba319b5SDimitry Andricconstexpr year_month_weekday
5124ba319b5SDimitry Andric  operator-(const year_month_weekday& ymwd, const years& dy) noexcept;
5134ba319b5SDimitry Andric
5144ba319b5SDimitry Andric// 25.8.17, class year_month_weekday_last    // C++20
5154ba319b5SDimitry Andricclass year_month_weekday_last;
5164ba319b5SDimitry Andric
5174ba319b5SDimitry Andricconstexpr bool operator==(const year_month_weekday_last& x,
5184ba319b5SDimitry Andric                          const year_month_weekday_last& y) noexcept;
5194ba319b5SDimitry Andricconstexpr bool operator!=(const year_month_weekday_last& x,
5204ba319b5SDimitry Andric                          const year_month_weekday_last& y) noexcept;
5214ba319b5SDimitry Andricconstexpr year_month_weekday_last
5224ba319b5SDimitry Andric  operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
5234ba319b5SDimitry Andricconstexpr year_month_weekday_last
5244ba319b5SDimitry Andric  operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept;
5254ba319b5SDimitry Andricconstexpr year_month_weekday_last
5264ba319b5SDimitry Andric  operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
5274ba319b5SDimitry Andricconstexpr year_month_weekday_last
5284ba319b5SDimitry Andric  operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept;
5294ba319b5SDimitry Andricconstexpr year_month_weekday_last
5304ba319b5SDimitry Andric  operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
5314ba319b5SDimitry Andricconstexpr year_month_weekday_last
5324ba319b5SDimitry Andric  operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
5334ba319b5SDimitry Andric
5344ba319b5SDimitry Andric// 25.8.18, civil calendar conventional syntax operators    // C++20
5354ba319b5SDimitry Andricconstexpr year_month
5364ba319b5SDimitry Andric  operator/(const year& y, const month& m) noexcept;
5374ba319b5SDimitry Andricconstexpr year_month
5384ba319b5SDimitry Andric  operator/(const year& y, int m) noexcept;
5394ba319b5SDimitry Andricconstexpr month_day
5404ba319b5SDimitry Andric  operator/(const month& m, const day& d) noexcept;
5414ba319b5SDimitry Andricconstexpr month_day
5424ba319b5SDimitry Andric  operator/(const month& m, int d) noexcept;
5434ba319b5SDimitry Andricconstexpr month_day
5444ba319b5SDimitry Andric  operator/(int m, const day& d) noexcept;
5454ba319b5SDimitry Andricconstexpr month_day
5464ba319b5SDimitry Andric  operator/(const day& d, const month& m) noexcept;
5474ba319b5SDimitry Andricconstexpr month_day
5484ba319b5SDimitry Andric  operator/(const day& d, int m) noexcept;
5494ba319b5SDimitry Andricconstexpr month_day_last
5504ba319b5SDimitry Andric  operator/(const month& m, last_spec) noexcept;
5514ba319b5SDimitry Andricconstexpr month_day_last
5524ba319b5SDimitry Andric  operator/(int m, last_spec) noexcept;
5534ba319b5SDimitry Andricconstexpr month_day_last
5544ba319b5SDimitry Andric  operator/(last_spec, const month& m) noexcept;
5554ba319b5SDimitry Andricconstexpr month_day_last
5564ba319b5SDimitry Andric  operator/(last_spec, int m) noexcept;
5574ba319b5SDimitry Andricconstexpr month_weekday
5584ba319b5SDimitry Andric  operator/(const month& m, const weekday_indexed& wdi) noexcept;
5594ba319b5SDimitry Andricconstexpr month_weekday
5604ba319b5SDimitry Andric  operator/(int m, const weekday_indexed& wdi) noexcept;
5614ba319b5SDimitry Andricconstexpr month_weekday
5624ba319b5SDimitry Andric  operator/(const weekday_indexed& wdi, const month& m) noexcept;
5634ba319b5SDimitry Andricconstexpr month_weekday
5644ba319b5SDimitry Andric  operator/(const weekday_indexed& wdi, int m) noexcept;
5654ba319b5SDimitry Andricconstexpr month_weekday_last
5664ba319b5SDimitry Andric  operator/(const month& m, const weekday_last& wdl) noexcept;
5674ba319b5SDimitry Andricconstexpr month_weekday_last
5684ba319b5SDimitry Andric  operator/(int m, const weekday_last& wdl) noexcept;
5694ba319b5SDimitry Andricconstexpr month_weekday_last
5704ba319b5SDimitry Andric  operator/(const weekday_last& wdl, const month& m) noexcept;
5714ba319b5SDimitry Andricconstexpr month_weekday_last
5724ba319b5SDimitry Andric  operator/(const weekday_last& wdl, int m) noexcept;
5734ba319b5SDimitry Andricconstexpr year_month_day
5744ba319b5SDimitry Andric  operator/(const year_month& ym, const day& d) noexcept;
5754ba319b5SDimitry Andricconstexpr year_month_day
5764ba319b5SDimitry Andric  operator/(const year_month& ym, int d) noexcept;
5774ba319b5SDimitry Andricconstexpr year_month_day
5784ba319b5SDimitry Andric  operator/(const year& y, const month_day& md) noexcept;
5794ba319b5SDimitry Andricconstexpr year_month_day
5804ba319b5SDimitry Andric  operator/(int y, const month_day& md) noexcept;
5814ba319b5SDimitry Andricconstexpr year_month_day
5824ba319b5SDimitry Andric  operator/(const month_day& md, const year& y) noexcept;
5834ba319b5SDimitry Andricconstexpr year_month_day
5844ba319b5SDimitry Andric  operator/(const month_day& md, int y) noexcept;
5854ba319b5SDimitry Andricconstexpr year_month_day_last
5864ba319b5SDimitry Andric  operator/(const year_month& ym, last_spec) noexcept;
5874ba319b5SDimitry Andricconstexpr year_month_day_last
5884ba319b5SDimitry Andric  operator/(const year& y, const month_day_last& mdl) noexcept;
5894ba319b5SDimitry Andricconstexpr year_month_day_last
5904ba319b5SDimitry Andric  operator/(int y, const month_day_last& mdl) noexcept;
5914ba319b5SDimitry Andricconstexpr year_month_day_last
5924ba319b5SDimitry Andric  operator/(const month_day_last& mdl, const year& y) noexcept;
5934ba319b5SDimitry Andricconstexpr year_month_day_last
5944ba319b5SDimitry Andric  operator/(const month_day_last& mdl, int y) noexcept;
5954ba319b5SDimitry Andricconstexpr year_month_weekday
5964ba319b5SDimitry Andric  operator/(const year_month& ym, const weekday_indexed& wdi) noexcept;
5974ba319b5SDimitry Andricconstexpr year_month_weekday
5984ba319b5SDimitry Andric  operator/(const year& y, const month_weekday& mwd) noexcept;
5994ba319b5SDimitry Andricconstexpr year_month_weekday
6004ba319b5SDimitry Andric  operator/(int y, const month_weekday& mwd) noexcept;
6014ba319b5SDimitry Andricconstexpr year_month_weekday
6024ba319b5SDimitry Andric  operator/(const month_weekday& mwd, const year& y) noexcept;
6034ba319b5SDimitry Andricconstexpr year_month_weekday
6044ba319b5SDimitry Andric  operator/(const month_weekday& mwd, int y) noexcept;
6054ba319b5SDimitry Andricconstexpr year_month_weekday_last
6064ba319b5SDimitry Andric  operator/(const year_month& ym, const weekday_last& wdl) noexcept;
6074ba319b5SDimitry Andricconstexpr year_month_weekday_last
6084ba319b5SDimitry Andric  operator/(const year& y, const month_weekday_last& mwdl) noexcept;
6094ba319b5SDimitry Andricconstexpr year_month_weekday_last
6104ba319b5SDimitry Andric  operator/(int y, const month_weekday_last& mwdl) noexcept;
6114ba319b5SDimitry Andricconstexpr year_month_weekday_last
6124ba319b5SDimitry Andric  operator/(const month_weekday_last& mwdl, const year& y) noexcept;
6134ba319b5SDimitry Andricconstexpr year_month_weekday_last
6144ba319b5SDimitry Andric  operator/(const month_weekday_last& mwdl, int y) noexcept;
6154ba319b5SDimitry Andric
6164ba319b5SDimitry Andric// 25.9, class template time_of_day    // C++20
6174ba319b5SDimitry Andrictemplate<class Duration> class time_of_day;
6184ba319b5SDimitry Andric
6194ba319b5SDimitry Andrictemplate<> class time_of_day<hours>;
6204ba319b5SDimitry Andrictemplate<> class time_of_day<minutes>;
6214ba319b5SDimitry Andrictemplate<> class time_of_day<seconds>;
6224ba319b5SDimitry Andrictemplate<class Rep, class Period> class time_of_day<duration<Rep, Period>>;
6234ba319b5SDimitry Andric
6244ba319b5SDimitry Andric// 25.10.2, time zone database     // C++20
6254ba319b5SDimitry Andricstruct tzdb;
6264ba319b5SDimitry Andricclass tzdb_list;
6274ba319b5SDimitry Andric
6284ba319b5SDimitry Andric// 25.10.2.3, time zone database access    // C++20
6294ba319b5SDimitry Andricconst tzdb& get_tzdb();
6304ba319b5SDimitry Andrictzdb_list& get_tzdb_list();
6314ba319b5SDimitry Andricconst time_zone* locate_zone(string_view tz_name);
6324ba319b5SDimitry Andricconst time_zone* current_zone();
6334ba319b5SDimitry Andric
6344ba319b5SDimitry Andric// 25.10.2.4, remote time zone database support    // C++20
6354ba319b5SDimitry Andricconst tzdb& reload_tzdb();
6364ba319b5SDimitry Andricstring remote_version();
6374ba319b5SDimitry Andric
6384ba319b5SDimitry Andric// 25.10.3, exception classes    // C++20
6394ba319b5SDimitry Andricclass nonexistent_local_time;
6404ba319b5SDimitry Andricclass ambiguous_local_time;
6414ba319b5SDimitry Andric
6424ba319b5SDimitry Andric// 25.10.4, information classes    // C++20
6434ba319b5SDimitry Andricstruct sys_info;
6444ba319b5SDimitry Andricstruct local_info;
6454ba319b5SDimitry Andric
6464ba319b5SDimitry Andric// 25.10.5, class time_zone    // C++20
6474ba319b5SDimitry Andricenum class choose {earliest, latest};
6484ba319b5SDimitry Andricclass time_zone;
6494ba319b5SDimitry Andricbool operator==(const time_zone& x, const time_zone& y) noexcept;
6504ba319b5SDimitry Andricbool operator!=(const time_zone& x, const time_zone& y) noexcept;
6514ba319b5SDimitry Andricbool operator<(const time_zone& x, const time_zone& y) noexcept;
6524ba319b5SDimitry Andricbool operator>(const time_zone& x, const time_zone& y) noexcept;
6534ba319b5SDimitry Andricbool operator<=(const time_zone& x, const time_zone& y) noexcept;
6544ba319b5SDimitry Andricbool operator>=(const time_zone& x, const time_zone& y) noexcept;
6554ba319b5SDimitry Andric
6564ba319b5SDimitry Andric// 25.10.6, class template zoned_traits    // C++20
6574ba319b5SDimitry Andrictemplate<class T> struct zoned_traits;
6584ba319b5SDimitry Andric
6594ba319b5SDimitry Andric// 25.10.7, class template zoned_time    // C++20
6604ba319b5SDimitry Andrictemplate<class Duration, class TimeZonePtr = const time_zone*> class zoned_time;
6614ba319b5SDimitry Andricusing zoned_seconds = zoned_time<seconds>;
6624ba319b5SDimitry Andric
6634ba319b5SDimitry Andrictemplate<class Duration1, class Duration2, class TimeZonePtr>
6644ba319b5SDimitry Andric  bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
6654ba319b5SDimitry Andric                  const zoned_time<Duration2, TimeZonePtr>& y);
6664ba319b5SDimitry Andrictemplate<class Duration1, class Duration2, class TimeZonePtr>
6674ba319b5SDimitry Andric  bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x,
6684ba319b5SDimitry Andric                  const zoned_time<Duration2, TimeZonePtr>& y);
6694ba319b5SDimitry Andric
6704ba319b5SDimitry Andric// 25.10.8, leap second support    // C++20
6714ba319b5SDimitry Andricclass leap;
6724ba319b5SDimitry Andric
6734ba319b5SDimitry Andricbool operator==(const leap& x, const leap& y);
6744ba319b5SDimitry Andricbool operator!=(const leap& x, const leap& y);
6754ba319b5SDimitry Andricbool operator< (const leap& x, const leap& y);
6764ba319b5SDimitry Andricbool operator> (const leap& x, const leap& y);
6774ba319b5SDimitry Andricbool operator<=(const leap& x, const leap& y);
6784ba319b5SDimitry Andricbool operator>=(const leap& x, const leap& y);
6794ba319b5SDimitry Andrictemplate<class Duration>
6804ba319b5SDimitry Andric  bool operator==(const leap& x, const sys_time<Duration>& y);
6814ba319b5SDimitry Andrictemplate<class Duration>
6824ba319b5SDimitry Andric  bool operator==(const sys_time<Duration>& x, const leap& y);
6834ba319b5SDimitry Andrictemplate<class Duration>
6844ba319b5SDimitry Andric  bool operator!=(const leap& x, const sys_time<Duration>& y);
6854ba319b5SDimitry Andrictemplate<class Duration>
6864ba319b5SDimitry Andric  bool operator!=(const sys_time<Duration>& x, const leap& y);
6874ba319b5SDimitry Andrictemplate<class Duration>
6884ba319b5SDimitry Andric  bool operator< (const leap& x, const sys_time<Duration>& y);
6894ba319b5SDimitry Andrictemplate<class Duration>
6904ba319b5SDimitry Andric  bool operator< (const sys_time<Duration>& x, const leap& y);
6914ba319b5SDimitry Andrictemplate<class Duration>
6924ba319b5SDimitry Andric  bool operator> (const leap& x, const sys_time<Duration>& y);
6934ba319b5SDimitry Andrictemplate<class Duration>
6944ba319b5SDimitry Andric  bool operator> (const sys_time<Duration>& x, const leap& y);
6954ba319b5SDimitry Andrictemplate<class Duration>
6964ba319b5SDimitry Andric  bool operator<=(const leap& x, const sys_time<Duration>& y);
6974ba319b5SDimitry Andrictemplate<class Duration>
6984ba319b5SDimitry Andric  bool operator<=(const sys_time<Duration>& x, const leap& y);
6994ba319b5SDimitry Andrictemplate<class Duration>
7004ba319b5SDimitry Andric  bool operator>=(const leap& x, const sys_time<Duration>& y);
7014ba319b5SDimitry Andrictemplate<class Duration>
7024ba319b5SDimitry Andric  bool operator>=(const sys_time<Duration>& x, const leap& y);
7034ba319b5SDimitry Andric
7044ba319b5SDimitry Andric// 25.10.9, class link    // C++20
7054ba319b5SDimitry Andricclass link;
7064ba319b5SDimitry Andricbool operator==(const link& x, const link& y);
7074ba319b5SDimitry Andricbool operator!=(const link& x, const link& y);
7084ba319b5SDimitry Andricbool operator< (const link& x, const link& y);
7094ba319b5SDimitry Andricbool operator> (const link& x, const link& y);
7104ba319b5SDimitry Andricbool operator<=(const link& x, const link& y);
7114ba319b5SDimitry Andricbool operator>=(const link& x, const link& y);
7124ba319b5SDimitry Andric
7134ba319b5SDimitry Andric// 25.11, formatting    // C++20
7144ba319b5SDimitry Andrictemplate<class charT, class Streamable>
7154ba319b5SDimitry Andric  basic_string<charT>
7164ba319b5SDimitry Andric    format(const charT* fmt, const Streamable& s);
7174ba319b5SDimitry Andric
7184ba319b5SDimitry Andrictemplate<class charT, class Streamable>
7194ba319b5SDimitry Andric  basic_string<charT>
7204ba319b5SDimitry Andric    format(const locale& loc, const charT* fmt, const Streamable& s);
7214ba319b5SDimitry Andric
7224ba319b5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Streamable>
7234ba319b5SDimitry Andric  basic_string<charT, traits, Alloc>
7244ba319b5SDimitry Andric    format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s);
7254ba319b5SDimitry Andric
7264ba319b5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Streamable>
7274ba319b5SDimitry Andric  basic_string<charT, traits, Alloc>
7284ba319b5SDimitry Andric    format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt,
7294ba319b5SDimitry Andric           const Streamable& s);
7304ba319b5SDimitry Andric
7314ba319b5SDimitry Andric// 25.12, parsing    // C++20
7324ba319b5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Parsable>
7334ba319b5SDimitry Andricunspecified
7344ba319b5SDimitry Andric    parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp);
7354ba319b5SDimitry Andric
7364ba319b5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Parsable>
7374ba319b5SDimitry Andricunspecified
7384ba319b5SDimitry Andric    parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
7394ba319b5SDimitry Andric          basic_string<charT, traits, Alloc>& abbrev);
7404ba319b5SDimitry Andric
7414ba319b5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Parsable>
7424ba319b5SDimitry Andricunspecified
7434ba319b5SDimitry Andric    parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
7444ba319b5SDimitry Andric          minutes& offset);
7454ba319b5SDimitry Andric
7464ba319b5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Parsable>
7474ba319b5SDimitry Andricunspecified
7484ba319b5SDimitry Andric    parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
7494ba319b5SDimitry Andric          basic_string<charT, traits, Alloc>& abbrev, minutes& offset);
7504ba319b5SDimitry Andric
751*b5893f02SDimitry Andric// calendrical constants
7524ba319b5SDimitry Andricinline constexpr last_spec                              last{};       // C++20
7534ba319b5SDimitry Andricinline constexpr chrono::weekday                        Sunday{0};    // C++20
7544ba319b5SDimitry Andricinline constexpr chrono::weekday                        Monday{1};    // C++20
7554ba319b5SDimitry Andricinline constexpr chrono::weekday                        Tuesday{2};   // C++20
7564ba319b5SDimitry Andricinline constexpr chrono::weekday                        Wednesday{3}; // C++20
7574ba319b5SDimitry Andricinline constexpr chrono::weekday                        Thursday{4};  // C++20
7584ba319b5SDimitry Andricinline constexpr chrono::weekday                        Friday{5};    // C++20
7594ba319b5SDimitry Andricinline constexpr chrono::weekday                        Saturday{6};  // C++20
7604ba319b5SDimitry Andric
7614ba319b5SDimitry Andricinline constexpr chrono::month                          January{1};   // C++20
7624ba319b5SDimitry Andricinline constexpr chrono::month                          February{2};  // C++20
7634ba319b5SDimitry Andricinline constexpr chrono::month                          March{3};     // C++20
7644ba319b5SDimitry Andricinline constexpr chrono::month                          April{4};     // C++20
7654ba319b5SDimitry Andricinline constexpr chrono::month                          May{5};       // C++20
7664ba319b5SDimitry Andricinline constexpr chrono::month                          June{6};      // C++20
7674ba319b5SDimitry Andricinline constexpr chrono::month                          July{7};      // C++20
7684ba319b5SDimitry Andricinline constexpr chrono::month                          August{8};    // C++20
7694ba319b5SDimitry Andricinline constexpr chrono::month                          September{9}; // C++20
7704ba319b5SDimitry Andricinline constexpr chrono::month                          October{10};  // C++20
7714ba319b5SDimitry Andricinline constexpr chrono::month                          November{11}; // C++20
7724ba319b5SDimitry Andricinline constexpr chrono::month                          December{12}; // C++20
7737a984708SDavid Chisnall}  // chrono
7747a984708SDavid Chisnall
7754ba319b5SDimitry Andricinline namespace literals {
7764ba319b5SDimitry Andric  inline namespace chrono_literals {
7774f7ab58eSDimitry Andricconstexpr chrono::hours                                 operator ""h(unsigned long long); // C++14
7784f7ab58eSDimitry Andricconstexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14
7794f7ab58eSDimitry Andricconstexpr chrono::minutes                               operator ""min(unsigned long long); // C++14
7804f7ab58eSDimitry Andricconstexpr chrono::duration<unspecified , ratio<60,1>>   operator ""min(long double); // C++14
7814f7ab58eSDimitry Andricconstexpr chrono::seconds                               operator ""s(unsigned long long); // C++14
7824f7ab58eSDimitry Andricconstexpr chrono::duration<unspecified >                operator ""s(long double); // C++14
7834f7ab58eSDimitry Andricconstexpr chrono::milliseconds                          operator ""ms(unsigned long long); // C++14
7844f7ab58eSDimitry Andricconstexpr chrono::duration<unspecified , milli>         operator ""ms(long double); // C++14
7854f7ab58eSDimitry Andricconstexpr chrono::microseconds                          operator ""us(unsigned long long); // C++14
7864f7ab58eSDimitry Andricconstexpr chrono::duration<unspecified , micro>         operator ""us(long double); // C++14
7874f7ab58eSDimitry Andricconstexpr chrono::nanoseconds                           operator ""ns(unsigned long long); // C++14
7884f7ab58eSDimitry Andricconstexpr chrono::duration<unspecified , nano>          operator ""ns(long double); // C++14
7894ba319b5SDimitry Andricconstexpr chrono::day                                   operator ""d(unsigned long long d) noexcept; // C++20
7904ba319b5SDimitry Andricconstexpr chrono::year                                  operator ""y(unsigned long long y) noexcept; // C++20
7914ba319b5SDimitry Andric}  // chrono_literals
7924ba319b5SDimitry Andric}  // literals
7934f7ab58eSDimitry Andric
7947a984708SDavid Chisnall}  // std
7957a984708SDavid Chisnall*/
7967a984708SDavid Chisnall
7977a984708SDavid Chisnall#include <__config>
7987a984708SDavid Chisnall#include <ctime>
7997a984708SDavid Chisnall#include <type_traits>
8007a984708SDavid Chisnall#include <ratio>
8017a984708SDavid Chisnall#include <limits>
802*b5893f02SDimitry Andric#include <version>
8037a984708SDavid Chisnall
8047a984708SDavid Chisnall#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
8057a984708SDavid Chisnall#pragma GCC system_header
8067a984708SDavid Chisnall#endif
8077a984708SDavid Chisnall
808f9448bf3SDimitry Andric_LIBCPP_PUSH_MACROS
809f9448bf3SDimitry Andric#include <__undef_macros>
810f9448bf3SDimitry Andric
811*b5893f02SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
812*b5893f02SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
813*b5893f02SDimitry Andricstruct _FilesystemClock;
814*b5893f02SDimitry Andric_LIBCPP_END_NAMESPACE_FILESYSTEM
815*b5893f02SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
816f9448bf3SDimitry Andric
8177a984708SDavid Chisnall_LIBCPP_BEGIN_NAMESPACE_STD
8187a984708SDavid Chisnall
8197a984708SDavid Chisnallnamespace chrono
8207a984708SDavid Chisnall{
8217a984708SDavid Chisnall
822aed8d94eSDimitry Andrictemplate <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
8237a984708SDavid Chisnall
8247a984708SDavid Chisnalltemplate <class _Tp>
8257a984708SDavid Chisnallstruct __is_duration : false_type {};
8267a984708SDavid Chisnall
8277a984708SDavid Chisnalltemplate <class _Rep, class _Period>
8287a984708SDavid Chisnallstruct __is_duration<duration<_Rep, _Period> > : true_type  {};
8297a984708SDavid Chisnall
8307a984708SDavid Chisnalltemplate <class _Rep, class _Period>
8317a984708SDavid Chisnallstruct __is_duration<const duration<_Rep, _Period> > : true_type  {};
8327a984708SDavid Chisnall
8337a984708SDavid Chisnalltemplate <class _Rep, class _Period>
8347a984708SDavid Chisnallstruct __is_duration<volatile duration<_Rep, _Period> > : true_type  {};
8357a984708SDavid Chisnall
8367a984708SDavid Chisnalltemplate <class _Rep, class _Period>
8377a984708SDavid Chisnallstruct __is_duration<const volatile duration<_Rep, _Period> > : true_type  {};
8387a984708SDavid Chisnall
8397a984708SDavid Chisnall} // chrono
8407a984708SDavid Chisnall
8417a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
842aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
8437a984708SDavid Chisnall                                         chrono::duration<_Rep2, _Period2> >
8447a984708SDavid Chisnall{
8457a984708SDavid Chisnall    typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
8467a984708SDavid Chisnall                             typename __ratio_gcd<_Period1, _Period2>::type> type;
8477a984708SDavid Chisnall};
8487a984708SDavid Chisnall
8497a984708SDavid Chisnallnamespace chrono {
8507a984708SDavid Chisnall
8517a984708SDavid Chisnall// duration_cast
8527a984708SDavid Chisnall
8537a984708SDavid Chisnalltemplate <class _FromDuration, class _ToDuration,
8547a984708SDavid Chisnall          class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
8557a984708SDavid Chisnall          bool = _Period::num == 1,
8567a984708SDavid Chisnall          bool = _Period::den == 1>
8577a984708SDavid Chisnallstruct __duration_cast;
8587a984708SDavid Chisnall
8597a984708SDavid Chisnalltemplate <class _FromDuration, class _ToDuration, class _Period>
8607a984708SDavid Chisnallstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
8617a984708SDavid Chisnall{
862936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
8637a984708SDavid Chisnall    _ToDuration operator()(const _FromDuration& __fd) const
8647a984708SDavid Chisnall    {
8657a984708SDavid Chisnall        return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
8667a984708SDavid Chisnall    }
8677a984708SDavid Chisnall};
8687a984708SDavid Chisnall
8697a984708SDavid Chisnalltemplate <class _FromDuration, class _ToDuration, class _Period>
8707a984708SDavid Chisnallstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
8717a984708SDavid Chisnall{
872936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
8737a984708SDavid Chisnall    _ToDuration operator()(const _FromDuration& __fd) const
8747a984708SDavid Chisnall    {
8757a984708SDavid Chisnall        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
8767a984708SDavid Chisnall        return _ToDuration(static_cast<typename _ToDuration::rep>(
8777a984708SDavid Chisnall                           static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
8787a984708SDavid Chisnall    }
8797a984708SDavid Chisnall};
8807a984708SDavid Chisnall
8817a984708SDavid Chisnalltemplate <class _FromDuration, class _ToDuration, class _Period>
8827a984708SDavid Chisnallstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
8837a984708SDavid Chisnall{
884936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
8857a984708SDavid Chisnall    _ToDuration operator()(const _FromDuration& __fd) const
8867a984708SDavid Chisnall    {
8877a984708SDavid Chisnall        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
8887a984708SDavid Chisnall        return _ToDuration(static_cast<typename _ToDuration::rep>(
8897a984708SDavid Chisnall                           static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
8907a984708SDavid Chisnall    }
8917a984708SDavid Chisnall};
8927a984708SDavid Chisnall
8937a984708SDavid Chisnalltemplate <class _FromDuration, class _ToDuration, class _Period>
8947a984708SDavid Chisnallstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
8957a984708SDavid Chisnall{
896936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
8977a984708SDavid Chisnall    _ToDuration operator()(const _FromDuration& __fd) const
8987a984708SDavid Chisnall    {
8997a984708SDavid Chisnall        typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
9007a984708SDavid Chisnall        return _ToDuration(static_cast<typename _ToDuration::rep>(
9017a984708SDavid Chisnall                           static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
9027a984708SDavid Chisnall                                                          / static_cast<_Ct>(_Period::den)));
9037a984708SDavid Chisnall    }
9047a984708SDavid Chisnall};
9057a984708SDavid Chisnall
9067a984708SDavid Chisnalltemplate <class _ToDuration, class _Rep, class _Period>
9077a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
908936e9439SDimitry Andric_LIBCPP_CONSTEXPR
9097a984708SDavid Chisnalltypename enable_if
9107a984708SDavid Chisnall<
9117a984708SDavid Chisnall    __is_duration<_ToDuration>::value,
9127a984708SDavid Chisnall    _ToDuration
9137a984708SDavid Chisnall>::type
9147a984708SDavid Chisnallduration_cast(const duration<_Rep, _Period>& __fd)
9157a984708SDavid Chisnall{
9167a984708SDavid Chisnall    return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
9177a984708SDavid Chisnall}
9187a984708SDavid Chisnall
9197a984708SDavid Chisnalltemplate <class _Rep>
920aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
9217a984708SDavid Chisnall
9229729cf09SDimitry Andric#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
92330785c0eSDimitry Andrictemplate <class _Rep>
92430785c0eSDimitry Andric_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
9259729cf09SDimitry Andric    = treat_as_floating_point<_Rep>::value;
9269729cf09SDimitry Andric#endif
9279729cf09SDimitry Andric
9287a984708SDavid Chisnalltemplate <class _Rep>
929aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS duration_values
9307a984708SDavid Chisnall{
9317a984708SDavid Chisnallpublic:
932*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
933*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max()  _NOEXCEPT {return numeric_limits<_Rep>::max();}
934*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min()  _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
9357a984708SDavid Chisnall};
9367a984708SDavid Chisnall
9379729cf09SDimitry Andric#if _LIBCPP_STD_VER > 14
9389729cf09SDimitry Andrictemplate <class _ToDuration, class _Rep, class _Period>
9399729cf09SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
9409729cf09SDimitry Andrictypename enable_if
9419729cf09SDimitry Andric<
9429729cf09SDimitry Andric    __is_duration<_ToDuration>::value,
9439729cf09SDimitry Andric    _ToDuration
9449729cf09SDimitry Andric>::type
9459729cf09SDimitry Andricfloor(const duration<_Rep, _Period>& __d)
9469729cf09SDimitry Andric{
9479729cf09SDimitry Andric    _ToDuration __t = duration_cast<_ToDuration>(__d);
9489729cf09SDimitry Andric    if (__t > __d)
9499729cf09SDimitry Andric        __t = __t - _ToDuration{1};
9509729cf09SDimitry Andric    return __t;
9519729cf09SDimitry Andric}
9529729cf09SDimitry Andric
9539729cf09SDimitry Andrictemplate <class _ToDuration, class _Rep, class _Period>
9549729cf09SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
9559729cf09SDimitry Andrictypename enable_if
9569729cf09SDimitry Andric<
9579729cf09SDimitry Andric    __is_duration<_ToDuration>::value,
9589729cf09SDimitry Andric    _ToDuration
9599729cf09SDimitry Andric>::type
9609729cf09SDimitry Andricceil(const duration<_Rep, _Period>& __d)
9619729cf09SDimitry Andric{
9629729cf09SDimitry Andric    _ToDuration __t = duration_cast<_ToDuration>(__d);
9639729cf09SDimitry Andric    if (__t < __d)
9649729cf09SDimitry Andric        __t = __t + _ToDuration{1};
9659729cf09SDimitry Andric    return __t;
9669729cf09SDimitry Andric}
9679729cf09SDimitry Andric
9689729cf09SDimitry Andrictemplate <class _ToDuration, class _Rep, class _Period>
9699729cf09SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
9709729cf09SDimitry Andrictypename enable_if
9719729cf09SDimitry Andric<
9729729cf09SDimitry Andric    __is_duration<_ToDuration>::value,
9739729cf09SDimitry Andric    _ToDuration
9749729cf09SDimitry Andric>::type
9759729cf09SDimitry Andricround(const duration<_Rep, _Period>& __d)
9769729cf09SDimitry Andric{
9779729cf09SDimitry Andric    _ToDuration __lower = floor<_ToDuration>(__d);
9789729cf09SDimitry Andric    _ToDuration __upper = __lower + _ToDuration{1};
9799729cf09SDimitry Andric    auto __lowerDiff = __d - __lower;
9809729cf09SDimitry Andric    auto __upperDiff = __upper - __d;
9819729cf09SDimitry Andric    if (__lowerDiff < __upperDiff)
9829729cf09SDimitry Andric        return __lower;
9839729cf09SDimitry Andric    if (__lowerDiff > __upperDiff)
9849729cf09SDimitry Andric        return __upper;
9859729cf09SDimitry Andric    return __lower.count() & 1 ? __upper : __lower;
9869729cf09SDimitry Andric}
9879729cf09SDimitry Andric#endif
9889729cf09SDimitry Andric
9897a984708SDavid Chisnall// duration
9907a984708SDavid Chisnall
9917a984708SDavid Chisnalltemplate <class _Rep, class _Period>
992aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS duration
9937a984708SDavid Chisnall{
9947a984708SDavid Chisnall    static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
9957a984708SDavid Chisnall    static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
9967a984708SDavid Chisnall    static_assert(_Period::num > 0, "duration period must be positive");
9974f7ab58eSDimitry Andric
9984f7ab58eSDimitry Andric    template <class _R1, class _R2>
9994f7ab58eSDimitry Andric    struct __no_overflow
10004f7ab58eSDimitry Andric    {
10014f7ab58eSDimitry Andric    private:
10024f7ab58eSDimitry Andric        static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
10034f7ab58eSDimitry Andric        static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
10044f7ab58eSDimitry Andric        static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
10054f7ab58eSDimitry Andric        static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
10064f7ab58eSDimitry Andric        static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
10074f7ab58eSDimitry Andric        static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
10084f7ab58eSDimitry Andric        static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
10094f7ab58eSDimitry Andric
10104f7ab58eSDimitry Andric        template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
10114f7ab58eSDimitry Andric        struct __mul    // __overflow == false
10124f7ab58eSDimitry Andric        {
10134f7ab58eSDimitry Andric            static const intmax_t value = _Xp * _Yp;
10144f7ab58eSDimitry Andric        };
10154f7ab58eSDimitry Andric
10164f7ab58eSDimitry Andric        template <intmax_t _Xp, intmax_t _Yp>
10174f7ab58eSDimitry Andric        struct __mul<_Xp, _Yp, true>
10184f7ab58eSDimitry Andric        {
10194f7ab58eSDimitry Andric            static const intmax_t value = 1;
10204f7ab58eSDimitry Andric        };
10214f7ab58eSDimitry Andric
10224f7ab58eSDimitry Andric    public:
10234f7ab58eSDimitry Andric        static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
10244f7ab58eSDimitry Andric        typedef ratio<__mul<__n1, __d2, !value>::value,
10254f7ab58eSDimitry Andric                      __mul<__n2, __d1, !value>::value> type;
10264f7ab58eSDimitry Andric    };
10274f7ab58eSDimitry Andric
10287a984708SDavid Chisnallpublic:
10297a984708SDavid Chisnall    typedef _Rep rep;
1030540d2a8bSDimitry Andric    typedef typename _Period::type period;
10317a984708SDavid Chisnallprivate:
10327a984708SDavid Chisnall    rep __rep_;
10337a984708SDavid Chisnallpublic:
10347a984708SDavid Chisnall
10354f7ab58eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
1036aed8d94eSDimitry Andric#ifndef _LIBCPP_CXX03_LANG
10374f7ab58eSDimitry Andric        duration() = default;
10384f7ab58eSDimitry Andric#else
10394f7ab58eSDimitry Andric        duration() {}
10404f7ab58eSDimitry Andric#endif
10414f7ab58eSDimitry Andric
10427a984708SDavid Chisnall    template <class _Rep2>
1043936e9439SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
10447a984708SDavid Chisnall        explicit duration(const _Rep2& __r,
10457a984708SDavid Chisnall            typename enable_if
10467a984708SDavid Chisnall            <
10477a984708SDavid Chisnall               is_convertible<_Rep2, rep>::value &&
10487a984708SDavid Chisnall               (treat_as_floating_point<rep>::value ||
10497a984708SDavid Chisnall               !treat_as_floating_point<_Rep2>::value)
10507a984708SDavid Chisnall            >::type* = 0)
10517a984708SDavid Chisnall                : __rep_(__r) {}
10527a984708SDavid Chisnall
10537a984708SDavid Chisnall    // conversions
10547a984708SDavid Chisnall    template <class _Rep2, class _Period2>
1055936e9439SDimitry Andric        _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
10567a984708SDavid Chisnall        duration(const duration<_Rep2, _Period2>& __d,
10577a984708SDavid Chisnall            typename enable_if
10587a984708SDavid Chisnall            <
10594f7ab58eSDimitry Andric                __no_overflow<_Period2, period>::value && (
10607a984708SDavid Chisnall                treat_as_floating_point<rep>::value ||
10614f7ab58eSDimitry Andric                (__no_overflow<_Period2, period>::type::den == 1 &&
10624f7ab58eSDimitry Andric                 !treat_as_floating_point<_Rep2>::value))
10637a984708SDavid Chisnall            >::type* = 0)
10647a984708SDavid Chisnall                : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
10657a984708SDavid Chisnall
10667a984708SDavid Chisnall    // observer
10677a984708SDavid Chisnall
1068936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
10697a984708SDavid Chisnall
10707a984708SDavid Chisnall    // arithmetic
10717a984708SDavid Chisnall
1072540d2a8bSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
1073540d2a8bSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
1074aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++()      {++__rep_; return *this;}
1075aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration  operator++(int)   {return duration(__rep_++);}
1076aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--()      {--__rep_; return *this;}
1077aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration  operator--(int)   {return duration(__rep_--);}
10787a984708SDavid Chisnall
1079aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
1080aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
10817a984708SDavid Chisnall
1082aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
1083aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
1084aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
1085aed8d94eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
10867a984708SDavid Chisnall
10877a984708SDavid Chisnall    // special values
10887a984708SDavid Chisnall
1089*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
1090*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min()  _NOEXCEPT {return duration(duration_values<rep>::min());}
1091*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max()  _NOEXCEPT {return duration(duration_values<rep>::max());}
10927a984708SDavid Chisnall};
10937a984708SDavid Chisnall
10947a984708SDavid Chisnalltypedef duration<long long,         nano> nanoseconds;
10957a984708SDavid Chisnalltypedef duration<long long,        micro> microseconds;
10967a984708SDavid Chisnalltypedef duration<long long,        milli> milliseconds;
10977a984708SDavid Chisnalltypedef duration<long long              > seconds;
10987a984708SDavid Chisnalltypedef duration<     long, ratio<  60> > minutes;
10997a984708SDavid Chisnalltypedef duration<     long, ratio<3600> > hours;
1100*b5893f02SDimitry Andric#if _LIBCPP_STD_VER > 17
1101*b5893f02SDimitry Andrictypedef duration<     int, ratio_multiply<ratio<24>, hours::period>>         days;
1102*b5893f02SDimitry Andrictypedef duration<     int, ratio_multiply<ratio<7>,   days::period>>         weeks;
1103*b5893f02SDimitry Andrictypedef duration<     int, ratio_multiply<ratio<146097, 400>, days::period>> years;
1104*b5893f02SDimitry Andrictypedef duration<     int, ratio_divide<years::period, ratio<12>>>           months;
1105*b5893f02SDimitry Andric#endif
11067a984708SDavid Chisnall// Duration ==
11077a984708SDavid Chisnall
11087a984708SDavid Chisnalltemplate <class _LhsDuration, class _RhsDuration>
11097a984708SDavid Chisnallstruct __duration_eq
11107a984708SDavid Chisnall{
1111936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
11129448dd00SDimitry Andric    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
11137a984708SDavid Chisnall        {
11147a984708SDavid Chisnall            typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
11157a984708SDavid Chisnall            return _Ct(__lhs).count() == _Ct(__rhs).count();
11167a984708SDavid Chisnall        }
11177a984708SDavid Chisnall};
11187a984708SDavid Chisnall
11197a984708SDavid Chisnalltemplate <class _LhsDuration>
11207a984708SDavid Chisnallstruct __duration_eq<_LhsDuration, _LhsDuration>
11217a984708SDavid Chisnall{
1122936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
11239448dd00SDimitry Andric    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
11247a984708SDavid Chisnall        {return __lhs.count() == __rhs.count();}
11257a984708SDavid Chisnall};
11267a984708SDavid Chisnall
11277a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
11287a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1129936e9439SDimitry Andric_LIBCPP_CONSTEXPR
11307a984708SDavid Chisnallbool
11317a984708SDavid Chisnalloperator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
11327a984708SDavid Chisnall{
11337a984708SDavid Chisnall    return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
11347a984708SDavid Chisnall}
11357a984708SDavid Chisnall
11367a984708SDavid Chisnall// Duration !=
11377a984708SDavid Chisnall
11387a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
11397a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1140936e9439SDimitry Andric_LIBCPP_CONSTEXPR
11417a984708SDavid Chisnallbool
11427a984708SDavid Chisnalloperator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
11437a984708SDavid Chisnall{
11447a984708SDavid Chisnall    return !(__lhs == __rhs);
11457a984708SDavid Chisnall}
11467a984708SDavid Chisnall
11477a984708SDavid Chisnall// Duration <
11487a984708SDavid Chisnall
11497a984708SDavid Chisnalltemplate <class _LhsDuration, class _RhsDuration>
11507a984708SDavid Chisnallstruct __duration_lt
11517a984708SDavid Chisnall{
1152936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
11539448dd00SDimitry Andric    bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
11547a984708SDavid Chisnall        {
11557a984708SDavid Chisnall            typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
11567a984708SDavid Chisnall            return _Ct(__lhs).count() < _Ct(__rhs).count();
11577a984708SDavid Chisnall        }
11587a984708SDavid Chisnall};
11597a984708SDavid Chisnall
11607a984708SDavid Chisnalltemplate <class _LhsDuration>
11617a984708SDavid Chisnallstruct __duration_lt<_LhsDuration, _LhsDuration>
11627a984708SDavid Chisnall{
1163936e9439SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
11649448dd00SDimitry Andric    bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
11657a984708SDavid Chisnall        {return __lhs.count() < __rhs.count();}
11667a984708SDavid Chisnall};
11677a984708SDavid Chisnall
11687a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
11697a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1170936e9439SDimitry Andric_LIBCPP_CONSTEXPR
11717a984708SDavid Chisnallbool
11727a984708SDavid Chisnalloperator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
11737a984708SDavid Chisnall{
11747a984708SDavid Chisnall    return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
11757a984708SDavid Chisnall}
11767a984708SDavid Chisnall
11777a984708SDavid Chisnall// Duration >
11787a984708SDavid Chisnall
11797a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
11807a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1181936e9439SDimitry Andric_LIBCPP_CONSTEXPR
11827a984708SDavid Chisnallbool
11837a984708SDavid Chisnalloperator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
11847a984708SDavid Chisnall{
11857a984708SDavid Chisnall    return __rhs < __lhs;
11867a984708SDavid Chisnall}
11877a984708SDavid Chisnall
11887a984708SDavid Chisnall// Duration <=
11897a984708SDavid Chisnall
11907a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
11917a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1192936e9439SDimitry Andric_LIBCPP_CONSTEXPR
11937a984708SDavid Chisnallbool
11947a984708SDavid Chisnalloperator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
11957a984708SDavid Chisnall{
11967a984708SDavid Chisnall    return !(__rhs < __lhs);
11977a984708SDavid Chisnall}
11987a984708SDavid Chisnall
11997a984708SDavid Chisnall// Duration >=
12007a984708SDavid Chisnall
12017a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
12027a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1203936e9439SDimitry Andric_LIBCPP_CONSTEXPR
12047a984708SDavid Chisnallbool
12057a984708SDavid Chisnalloperator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
12067a984708SDavid Chisnall{
12077a984708SDavid Chisnall    return !(__lhs < __rhs);
12087a984708SDavid Chisnall}
12097a984708SDavid Chisnall
12107a984708SDavid Chisnall// Duration +
12117a984708SDavid Chisnall
12127a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
12137a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1214936e9439SDimitry Andric_LIBCPP_CONSTEXPR
12157a984708SDavid Chisnalltypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
12167a984708SDavid Chisnalloperator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
12177a984708SDavid Chisnall{
1218936e9439SDimitry Andric    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1219936e9439SDimitry Andric    return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
12207a984708SDavid Chisnall}
12217a984708SDavid Chisnall
12227a984708SDavid Chisnall// Duration -
12237a984708SDavid Chisnall
12247a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
12257a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1226936e9439SDimitry Andric_LIBCPP_CONSTEXPR
12277a984708SDavid Chisnalltypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
12287a984708SDavid Chisnalloperator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
12297a984708SDavid Chisnall{
1230936e9439SDimitry Andric    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1231936e9439SDimitry Andric    return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
12327a984708SDavid Chisnall}
12337a984708SDavid Chisnall
12347a984708SDavid Chisnall// Duration *
12357a984708SDavid Chisnall
12367a984708SDavid Chisnalltemplate <class _Rep1, class _Period, class _Rep2>
12377a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1238936e9439SDimitry Andric_LIBCPP_CONSTEXPR
12397a984708SDavid Chisnalltypename enable_if
12407a984708SDavid Chisnall<
12417a984708SDavid Chisnall    is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
12427a984708SDavid Chisnall    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
12437a984708SDavid Chisnall>::type
12447a984708SDavid Chisnalloperator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
12457a984708SDavid Chisnall{
12467a984708SDavid Chisnall    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1247936e9439SDimitry Andric    typedef duration<_Cr, _Period> _Cd;
1248936e9439SDimitry Andric    return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
12497a984708SDavid Chisnall}
12507a984708SDavid Chisnall
12517a984708SDavid Chisnalltemplate <class _Rep1, class _Period, class _Rep2>
12527a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1253936e9439SDimitry Andric_LIBCPP_CONSTEXPR
12547a984708SDavid Chisnalltypename enable_if
12557a984708SDavid Chisnall<
12567a984708SDavid Chisnall    is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
12577a984708SDavid Chisnall    duration<typename common_type<_Rep1, _Rep2>::type, _Period>
12587a984708SDavid Chisnall>::type
12597a984708SDavid Chisnalloperator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
12607a984708SDavid Chisnall{
12617a984708SDavid Chisnall    return __d * __s;
12627a984708SDavid Chisnall}
12637a984708SDavid Chisnall
12647a984708SDavid Chisnall// Duration /
12657a984708SDavid Chisnall
12667a984708SDavid Chisnalltemplate <class _Duration, class _Rep, bool = __is_duration<_Rep>::value>
12677a984708SDavid Chisnallstruct __duration_divide_result
12687a984708SDavid Chisnall{
12697a984708SDavid Chisnall};
12707a984708SDavid Chisnall
12717a984708SDavid Chisnalltemplate <class _Duration, class _Rep2,
12727a984708SDavid Chisnall    bool = is_convertible<_Rep2,
12737a984708SDavid Chisnall                          typename common_type<typename _Duration::rep, _Rep2>::type>::value>
12747a984708SDavid Chisnallstruct __duration_divide_imp
12757a984708SDavid Chisnall{
12767a984708SDavid Chisnall};
12777a984708SDavid Chisnall
12787a984708SDavid Chisnalltemplate <class _Rep1, class _Period, class _Rep2>
12797a984708SDavid Chisnallstruct __duration_divide_imp<duration<_Rep1, _Period>, _Rep2, true>
12807a984708SDavid Chisnall{
12817a984708SDavid Chisnall    typedef duration<typename common_type<_Rep1, _Rep2>::type, _Period> type;
12827a984708SDavid Chisnall};
12837a984708SDavid Chisnall
12847a984708SDavid Chisnalltemplate <class _Rep1, class _Period, class _Rep2>
12857a984708SDavid Chisnallstruct __duration_divide_result<duration<_Rep1, _Period>, _Rep2, false>
12867a984708SDavid Chisnall    : __duration_divide_imp<duration<_Rep1, _Period>, _Rep2>
12877a984708SDavid Chisnall{
12887a984708SDavid Chisnall};
12897a984708SDavid Chisnall
12907a984708SDavid Chisnalltemplate <class _Rep1, class _Period, class _Rep2>
12917a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1292936e9439SDimitry Andric_LIBCPP_CONSTEXPR
12937a984708SDavid Chisnalltypename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
12947a984708SDavid Chisnalloperator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
12957a984708SDavid Chisnall{
12967a984708SDavid Chisnall    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1297936e9439SDimitry Andric    typedef duration<_Cr, _Period> _Cd;
1298936e9439SDimitry Andric    return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
12997a984708SDavid Chisnall}
13007a984708SDavid Chisnall
13017a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
13027a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1303936e9439SDimitry Andric_LIBCPP_CONSTEXPR
13047a984708SDavid Chisnalltypename common_type<_Rep1, _Rep2>::type
13057a984708SDavid Chisnalloperator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
13067a984708SDavid Chisnall{
13077a984708SDavid Chisnall    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
13087a984708SDavid Chisnall    return _Ct(__lhs).count() / _Ct(__rhs).count();
13097a984708SDavid Chisnall}
13107a984708SDavid Chisnall
13117a984708SDavid Chisnall// Duration %
13127a984708SDavid Chisnall
13137a984708SDavid Chisnalltemplate <class _Rep1, class _Period, class _Rep2>
13147a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1315936e9439SDimitry Andric_LIBCPP_CONSTEXPR
13167a984708SDavid Chisnalltypename __duration_divide_result<duration<_Rep1, _Period>, _Rep2>::type
13177a984708SDavid Chisnalloperator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
13187a984708SDavid Chisnall{
13197a984708SDavid Chisnall    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1320936e9439SDimitry Andric    typedef duration<_Cr, _Period> _Cd;
1321936e9439SDimitry Andric    return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
13227a984708SDavid Chisnall}
13237a984708SDavid Chisnall
13247a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Rep2, class _Period2>
13257a984708SDavid Chisnallinline _LIBCPP_INLINE_VISIBILITY
1326936e9439SDimitry Andric_LIBCPP_CONSTEXPR
13277a984708SDavid Chisnalltypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
13287a984708SDavid Chisnalloperator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
13297a984708SDavid Chisnall{
1330936e9439SDimitry Andric    typedef typename common_type<_Rep1, _Rep2>::type _Cr;
1331936e9439SDimitry Andric    typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
1332936e9439SDimitry Andric    return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
13337a984708SDavid Chisnall}
13347a984708SDavid Chisnall
13357a984708SDavid Chisnall//////////////////////////////////////////////////////////
13367a984708SDavid Chisnall///////////////////// time_point /////////////////////////
13377a984708SDavid Chisnall//////////////////////////////////////////////////////////
13387a984708SDavid Chisnall
13397a984708SDavid Chisnalltemplate <class _Clock, class _Duration = typename _Clock::duration>
1340aed8d94eSDimitry Andricclass _LIBCPP_TEMPLATE_VIS time_point
13417a984708SDavid Chisnall{
13427a984708SDavid Chisnall    static_assert(__is_duration<_Duration>::value,
13437a984708SDavid Chisnall                  "Second template parameter of time_point must be a std::chrono::duration");
13447a984708SDavid Chisnallpublic:
13457a984708SDavid Chisnall    typedef _Clock                    clock;
13467a984708SDavid Chisnall    typedef _Duration                 duration;
13477a984708SDavid Chisnall    typedef typename duration::rep    rep;
13487a984708SDavid Chisnall    typedef typename duration::period period;
13497a984708SDavid Chisnallprivate:
13507a984708SDavid Chisnall    duration __d_;
13517a984708SDavid Chisnall
13527a984708SDavid Chisnallpublic:
13534f7ab58eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
13544f7ab58eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
13557a984708SDavid Chisnall
13567a984708SDavid Chisnall    // conversions
13577a984708SDavid Chisnall    template <class _Duration2>
13584f7ab58eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
13597a984708SDavid Chisnall    time_point(const time_point<clock, _Duration2>& t,
13607a984708SDavid Chisnall        typename enable_if
13617a984708SDavid Chisnall        <
13627a984708SDavid Chisnall            is_convertible<_Duration2, duration>::value
13637a984708SDavid Chisnall        >::type* = 0)
13647a984708SDavid Chisnall            : __d_(t.time_since_epoch()) {}
13657a984708SDavid Chisnall
13667a984708SDavid Chisnall    // observer
13677a984708SDavid Chisnall
13684f7ab58eSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
13697a984708SDavid Chisnall
13707a984708SDavid Chisnall    // arithmetic
13717a984708SDavid Chisnall
1372*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
1373*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
13747a984708SDavid Chisnall
13757a984708SDavid Chisnall    // special values
13767a984708SDavid Chisnall
1377*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
1378*b5893f02SDimitry Andric    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
13797a984708SDavid Chisnall};
13807a984708SDavid Chisnall
13817a984708SDavid Chisnall} // chrono
13827a984708SDavid Chisnall
13837a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Duration2>
1384aed8d94eSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
13857a984708SDavid Chisnall                                         chrono::time_point<_Clock, _Duration2> >
13867a984708SDavid Chisnall{
13877a984708SDavid Chisnall    typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
13887a984708SDavid Chisnall};
13897a984708SDavid Chisnall
13907a984708SDavid Chisnallnamespace chrono {
13917a984708SDavid Chisnall
13927a984708SDavid Chisnalltemplate <class _ToDuration, class _Clock, class _Duration>
13934f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
13947a984708SDavid Chisnalltime_point<_Clock, _ToDuration>
13957a984708SDavid Chisnalltime_point_cast(const time_point<_Clock, _Duration>& __t)
13967a984708SDavid Chisnall{
13977a984708SDavid Chisnall    return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
13987a984708SDavid Chisnall}
13997a984708SDavid Chisnall
14009729cf09SDimitry Andric#if _LIBCPP_STD_VER > 14
14019729cf09SDimitry Andrictemplate <class _ToDuration, class _Clock, class _Duration>
14029729cf09SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
14039729cf09SDimitry Andrictypename enable_if
14049729cf09SDimitry Andric<
14059729cf09SDimitry Andric    __is_duration<_ToDuration>::value,
14069729cf09SDimitry Andric    time_point<_Clock, _ToDuration>
14079729cf09SDimitry Andric>::type
14089729cf09SDimitry Andricfloor(const time_point<_Clock, _Duration>& __t)
14099729cf09SDimitry Andric{
14109729cf09SDimitry Andric    return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
14119729cf09SDimitry Andric}
14129729cf09SDimitry Andric
14139729cf09SDimitry Andrictemplate <class _ToDuration, class _Clock, class _Duration>
14149729cf09SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
14159729cf09SDimitry Andrictypename enable_if
14169729cf09SDimitry Andric<
14179729cf09SDimitry Andric    __is_duration<_ToDuration>::value,
14189729cf09SDimitry Andric    time_point<_Clock, _ToDuration>
14199729cf09SDimitry Andric>::type
14209729cf09SDimitry Andricceil(const time_point<_Clock, _Duration>& __t)
14219729cf09SDimitry Andric{
14229729cf09SDimitry Andric    return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
14239729cf09SDimitry Andric}
14249729cf09SDimitry Andric
14259729cf09SDimitry Andrictemplate <class _ToDuration, class _Clock, class _Duration>
14269729cf09SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
14279729cf09SDimitry Andrictypename enable_if
14289729cf09SDimitry Andric<
14299729cf09SDimitry Andric    __is_duration<_ToDuration>::value,
14309729cf09SDimitry Andric    time_point<_Clock, _ToDuration>
14319729cf09SDimitry Andric>::type
14329729cf09SDimitry Andricround(const time_point<_Clock, _Duration>& __t)
14339729cf09SDimitry Andric{
14349729cf09SDimitry Andric    return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
14359729cf09SDimitry Andric}
14369729cf09SDimitry Andric
14379729cf09SDimitry Andrictemplate <class _Rep, class _Period>
14389729cf09SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
14399729cf09SDimitry Andrictypename enable_if
14409729cf09SDimitry Andric<
14419729cf09SDimitry Andric    numeric_limits<_Rep>::is_signed,
14429729cf09SDimitry Andric    duration<_Rep, _Period>
14439729cf09SDimitry Andric>::type
14449729cf09SDimitry Andricabs(duration<_Rep, _Period> __d)
14459729cf09SDimitry Andric{
14469729cf09SDimitry Andric    return __d >= __d.zero() ? __d : -__d;
14479729cf09SDimitry Andric}
14489729cf09SDimitry Andric#endif
14499729cf09SDimitry Andric
14507a984708SDavid Chisnall// time_point ==
14517a984708SDavid Chisnall
14527a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Duration2>
14534f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
14547a984708SDavid Chisnallbool
14557a984708SDavid Chisnalloperator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
14567a984708SDavid Chisnall{
14577a984708SDavid Chisnall    return __lhs.time_since_epoch() == __rhs.time_since_epoch();
14587a984708SDavid Chisnall}
14597a984708SDavid Chisnall
14607a984708SDavid Chisnall// time_point !=
14617a984708SDavid Chisnall
14627a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Duration2>
14634f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
14647a984708SDavid Chisnallbool
14657a984708SDavid Chisnalloperator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
14667a984708SDavid Chisnall{
14677a984708SDavid Chisnall    return !(__lhs == __rhs);
14687a984708SDavid Chisnall}
14697a984708SDavid Chisnall
14707a984708SDavid Chisnall// time_point <
14717a984708SDavid Chisnall
14727a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Duration2>
14734f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
14747a984708SDavid Chisnallbool
14757a984708SDavid Chisnalloperator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
14767a984708SDavid Chisnall{
14777a984708SDavid Chisnall    return __lhs.time_since_epoch() < __rhs.time_since_epoch();
14787a984708SDavid Chisnall}
14797a984708SDavid Chisnall
14807a984708SDavid Chisnall// time_point >
14817a984708SDavid Chisnall
14827a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Duration2>
14834f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
14847a984708SDavid Chisnallbool
14857a984708SDavid Chisnalloperator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
14867a984708SDavid Chisnall{
14877a984708SDavid Chisnall    return __rhs < __lhs;
14887a984708SDavid Chisnall}
14897a984708SDavid Chisnall
14907a984708SDavid Chisnall// time_point <=
14917a984708SDavid Chisnall
14927a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Duration2>
14934f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
14947a984708SDavid Chisnallbool
14957a984708SDavid Chisnalloperator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
14967a984708SDavid Chisnall{
14977a984708SDavid Chisnall    return !(__rhs < __lhs);
14987a984708SDavid Chisnall}
14997a984708SDavid Chisnall
15007a984708SDavid Chisnall// time_point >=
15017a984708SDavid Chisnall
15027a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Duration2>
15034f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
15047a984708SDavid Chisnallbool
15057a984708SDavid Chisnalloperator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
15067a984708SDavid Chisnall{
15077a984708SDavid Chisnall    return !(__lhs < __rhs);
15087a984708SDavid Chisnall}
15097a984708SDavid Chisnall
15107a984708SDavid Chisnall// time_point operator+(time_point x, duration y);
15117a984708SDavid Chisnall
15127a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Rep2, class _Period2>
15134f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
15147a984708SDavid Chisnalltime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
15157a984708SDavid Chisnalloperator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
15167a984708SDavid Chisnall{
15177a984708SDavid Chisnall    typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
15184f7ab58eSDimitry Andric    return _Tr (__lhs.time_since_epoch() + __rhs);
15197a984708SDavid Chisnall}
15207a984708SDavid Chisnall
15217a984708SDavid Chisnall// time_point operator+(duration x, time_point y);
15227a984708SDavid Chisnall
15237a984708SDavid Chisnalltemplate <class _Rep1, class _Period1, class _Clock, class _Duration2>
15244f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
15257a984708SDavid Chisnalltime_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
15267a984708SDavid Chisnalloperator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
15277a984708SDavid Chisnall{
15287a984708SDavid Chisnall    return __rhs + __lhs;
15297a984708SDavid Chisnall}
15307a984708SDavid Chisnall
15317a984708SDavid Chisnall// time_point operator-(time_point x, duration y);
15327a984708SDavid Chisnall
15337a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Rep2, class _Period2>
15344f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
15357a984708SDavid Chisnalltime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
15367a984708SDavid Chisnalloperator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
15377a984708SDavid Chisnall{
1538aed8d94eSDimitry Andric    typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
1539aed8d94eSDimitry Andric    return _Ret(__lhs.time_since_epoch() -__rhs);
15407a984708SDavid Chisnall}
15417a984708SDavid Chisnall
15427a984708SDavid Chisnall// duration operator-(time_point x, time_point y);
15437a984708SDavid Chisnall
15447a984708SDavid Chisnalltemplate <class _Clock, class _Duration1, class _Duration2>
15454f7ab58eSDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
15467a984708SDavid Chisnalltypename common_type<_Duration1, _Duration2>::type
15477a984708SDavid Chisnalloperator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
15487a984708SDavid Chisnall{
15497a984708SDavid Chisnall    return __lhs.time_since_epoch() - __rhs.time_since_epoch();
15507a984708SDavid Chisnall}
15517a984708SDavid Chisnall
15527a984708SDavid Chisnall//////////////////////////////////////////////////////////
15537a984708SDavid Chisnall/////////////////////// clocks ///////////////////////////
15547a984708SDavid Chisnall//////////////////////////////////////////////////////////
15557a984708SDavid Chisnall
15561bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS system_clock
15577a984708SDavid Chisnall{
15587a984708SDavid Chisnallpublic:
15597a984708SDavid Chisnall    typedef microseconds                     duration;
15607a984708SDavid Chisnall    typedef duration::rep                    rep;
15617a984708SDavid Chisnall    typedef duration::period                 period;
15627a984708SDavid Chisnall    typedef chrono::time_point<system_clock> time_point;
15634f7ab58eSDimitry Andric    static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
15647a984708SDavid Chisnall
15657a984708SDavid Chisnall    static time_point now() _NOEXCEPT;
15667a984708SDavid Chisnall    static time_t     to_time_t  (const time_point& __t) _NOEXCEPT;
15677a984708SDavid Chisnall    static time_point from_time_t(time_t __t) _NOEXCEPT;
15687a984708SDavid Chisnall};
15697a984708SDavid Chisnall
1570d72607e9SDimitry Andric#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
15711bf9f7c1SDimitry Andricclass _LIBCPP_TYPE_VIS steady_clock
15727a984708SDavid Chisnall{
15737a984708SDavid Chisnallpublic:
15747a984708SDavid Chisnall    typedef nanoseconds                                   duration;
15757a984708SDavid Chisnall    typedef duration::rep                                 rep;
15767a984708SDavid Chisnall    typedef duration::period                              period;
15777a984708SDavid Chisnall    typedef chrono::time_point<steady_clock, duration>    time_point;
15784f7ab58eSDimitry Andric    static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
15797a984708SDavid Chisnall
15807a984708SDavid Chisnall    static time_point now() _NOEXCEPT;
15817a984708SDavid Chisnall};
15827a984708SDavid Chisnall
15837a984708SDavid Chisnalltypedef steady_clock high_resolution_clock;
1584d72607e9SDimitry Andric#else
1585d72607e9SDimitry Andrictypedef system_clock high_resolution_clock;
1586d72607e9SDimitry Andric#endif
15877a984708SDavid Chisnall
1588*b5893f02SDimitry Andric#if _LIBCPP_STD_VER > 17
1589*b5893f02SDimitry Andric// [time.clock.file], type file_clock
1590*b5893f02SDimitry Andricusing file_clock = _VSTD_FS::_FilesystemClock;
1591*b5893f02SDimitry Andric
1592*b5893f02SDimitry Andrictemplate<class _Duration>
1593*b5893f02SDimitry Andricusing file_time = time_point<file_clock, _Duration>;
1594*b5893f02SDimitry Andric
1595*b5893f02SDimitry Andric
1596*b5893f02SDimitry Andrictemplate <class _Duration>
1597*b5893f02SDimitry Andricusing sys_time    = time_point<system_clock, _Duration>;
1598*b5893f02SDimitry Andricusing sys_seconds = sys_time<seconds>;
1599*b5893f02SDimitry Andricusing sys_days    = sys_time<days>;
1600*b5893f02SDimitry Andric
1601*b5893f02SDimitry Andricstruct local_t {};
1602*b5893f02SDimitry Andrictemplate<class Duration>
1603*b5893f02SDimitry Andricusing local_time  = time_point<local_t, Duration>;
1604*b5893f02SDimitry Andricusing local_seconds = local_time<seconds>;
1605*b5893f02SDimitry Andricusing local_days    = local_time<days>;
1606*b5893f02SDimitry Andric
1607*b5893f02SDimitry Andric
1608*b5893f02SDimitry Andricstruct _LIBCPP_TYPE_VIS last_spec { explicit last_spec() = default; };
1609*b5893f02SDimitry Andric
1610*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS day {
1611*b5893f02SDimitry Andricprivate:
1612*b5893f02SDimitry Andric    unsigned char __d;
1613*b5893f02SDimitry Andricpublic:
1614*b5893f02SDimitry Andric    day() = default;
1615*b5893f02SDimitry Andric    explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
1616*b5893f02SDimitry Andric    inline constexpr day& operator++()    noexcept { ++__d; return *this; }
1617*b5893f02SDimitry Andric    inline constexpr day  operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
1618*b5893f02SDimitry Andric    inline constexpr day& operator--()    noexcept { --__d; return *this; }
1619*b5893f02SDimitry Andric    inline constexpr day  operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
1620*b5893f02SDimitry Andric           constexpr day& operator+=(const days& __dd) noexcept;
1621*b5893f02SDimitry Andric           constexpr day& operator-=(const days& __dd) noexcept;
1622*b5893f02SDimitry Andric    explicit inline constexpr operator unsigned() const noexcept { return __d; }
1623*b5893f02SDimitry Andric    inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
1624*b5893f02SDimitry Andric  };
1625*b5893f02SDimitry Andric
1626*b5893f02SDimitry Andric
1627*b5893f02SDimitry Andricinline constexpr
1628*b5893f02SDimitry Andricbool operator==(const day& __lhs, const day& __rhs) noexcept
1629*b5893f02SDimitry Andric{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1630*b5893f02SDimitry Andric
1631*b5893f02SDimitry Andricinline constexpr
1632*b5893f02SDimitry Andricbool operator!=(const day& __lhs, const day& __rhs) noexcept
1633*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
1634*b5893f02SDimitry Andric
1635*b5893f02SDimitry Andricinline constexpr
1636*b5893f02SDimitry Andricbool operator< (const day& __lhs, const day& __rhs) noexcept
1637*b5893f02SDimitry Andric{ return static_cast<unsigned>(__lhs) <  static_cast<unsigned>(__rhs); }
1638*b5893f02SDimitry Andric
1639*b5893f02SDimitry Andricinline constexpr
1640*b5893f02SDimitry Andricbool operator> (const day& __lhs, const day& __rhs) noexcept
1641*b5893f02SDimitry Andric{ return __rhs < __lhs; }
1642*b5893f02SDimitry Andric
1643*b5893f02SDimitry Andricinline constexpr
1644*b5893f02SDimitry Andricbool operator<=(const day& __lhs, const day& __rhs) noexcept
1645*b5893f02SDimitry Andric{ return !(__rhs < __lhs);}
1646*b5893f02SDimitry Andric
1647*b5893f02SDimitry Andricinline constexpr
1648*b5893f02SDimitry Andricbool operator>=(const day& __lhs, const day& __rhs) noexcept
1649*b5893f02SDimitry Andric{ return !(__lhs < __rhs); }
1650*b5893f02SDimitry Andric
1651*b5893f02SDimitry Andricinline constexpr
1652*b5893f02SDimitry Andricday operator+ (const day& __lhs, const days& __rhs) noexcept
1653*b5893f02SDimitry Andric{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
1654*b5893f02SDimitry Andric
1655*b5893f02SDimitry Andricinline constexpr
1656*b5893f02SDimitry Andricday operator+ (const days& __lhs, const day& __rhs) noexcept
1657*b5893f02SDimitry Andric{ return __rhs + __lhs; }
1658*b5893f02SDimitry Andric
1659*b5893f02SDimitry Andricinline constexpr
1660*b5893f02SDimitry Andricday operator- (const day& __lhs, const days& __rhs) noexcept
1661*b5893f02SDimitry Andric{ return __lhs + -__rhs; }
1662*b5893f02SDimitry Andric
1663*b5893f02SDimitry Andricinline constexpr
1664*b5893f02SDimitry Andricdays operator-(const day& __lhs, const day& __rhs) noexcept
1665*b5893f02SDimitry Andric{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
1666*b5893f02SDimitry Andric              static_cast<int>(static_cast<unsigned>(__rhs))); }
1667*b5893f02SDimitry Andric
1668*b5893f02SDimitry Andricinline constexpr day& day::operator+=(const days& __dd) noexcept
1669*b5893f02SDimitry Andric{ *this = *this + __dd; return *this; }
1670*b5893f02SDimitry Andric
1671*b5893f02SDimitry Andricinline constexpr day& day::operator-=(const days& __dd) noexcept
1672*b5893f02SDimitry Andric{ *this = *this - __dd; return *this; }
1673*b5893f02SDimitry Andric
1674*b5893f02SDimitry Andric
1675*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS month {
1676*b5893f02SDimitry Andricprivate:
1677*b5893f02SDimitry Andric    unsigned char __m;
1678*b5893f02SDimitry Andricpublic:
1679*b5893f02SDimitry Andric    month() = default;
1680*b5893f02SDimitry Andric    explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
1681*b5893f02SDimitry Andric    inline constexpr month& operator++()    noexcept { ++__m; return *this; }
1682*b5893f02SDimitry Andric    inline constexpr month  operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
1683*b5893f02SDimitry Andric    inline constexpr month& operator--()    noexcept { --__m; return *this; }
1684*b5893f02SDimitry Andric    inline constexpr month  operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
1685*b5893f02SDimitry Andric           constexpr month& operator+=(const months& __m1) noexcept;
1686*b5893f02SDimitry Andric           constexpr month& operator-=(const months& __m1) noexcept;
1687*b5893f02SDimitry Andric    explicit inline constexpr operator unsigned() const noexcept { return __m; }
1688*b5893f02SDimitry Andric    inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
1689*b5893f02SDimitry Andric};
1690*b5893f02SDimitry Andric
1691*b5893f02SDimitry Andric
1692*b5893f02SDimitry Andricinline constexpr
1693*b5893f02SDimitry Andricbool operator==(const month& __lhs, const month& __rhs) noexcept
1694*b5893f02SDimitry Andric{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1695*b5893f02SDimitry Andric
1696*b5893f02SDimitry Andricinline constexpr
1697*b5893f02SDimitry Andricbool operator!=(const month& __lhs, const month& __rhs) noexcept
1698*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
1699*b5893f02SDimitry Andric
1700*b5893f02SDimitry Andricinline constexpr
1701*b5893f02SDimitry Andricbool operator< (const month& __lhs, const month& __rhs) noexcept
1702*b5893f02SDimitry Andric{ return static_cast<unsigned>(__lhs)  < static_cast<unsigned>(__rhs); }
1703*b5893f02SDimitry Andric
1704*b5893f02SDimitry Andricinline constexpr
1705*b5893f02SDimitry Andricbool operator> (const month& __lhs, const month& __rhs) noexcept
1706*b5893f02SDimitry Andric{ return __rhs < __lhs; }
1707*b5893f02SDimitry Andric
1708*b5893f02SDimitry Andricinline constexpr
1709*b5893f02SDimitry Andricbool operator<=(const month& __lhs, const month& __rhs) noexcept
1710*b5893f02SDimitry Andric{ return !(__rhs < __lhs); }
1711*b5893f02SDimitry Andric
1712*b5893f02SDimitry Andricinline constexpr
1713*b5893f02SDimitry Andricbool operator>=(const month& __lhs, const month& __rhs) noexcept
1714*b5893f02SDimitry Andric{ return !(__lhs < __rhs); }
1715*b5893f02SDimitry Andric
1716*b5893f02SDimitry Andricinline constexpr
1717*b5893f02SDimitry Andricmonth operator+ (const month& __lhs, const months& __rhs) noexcept
1718*b5893f02SDimitry Andric{
1719*b5893f02SDimitry Andric    auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
1720*b5893f02SDimitry Andric    auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
1721*b5893f02SDimitry Andric    return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
1722*b5893f02SDimitry Andric}
1723*b5893f02SDimitry Andric
1724*b5893f02SDimitry Andricinline constexpr
1725*b5893f02SDimitry Andricmonth operator+ (const months& __lhs, const month& __rhs) noexcept
1726*b5893f02SDimitry Andric{ return __rhs + __lhs; }
1727*b5893f02SDimitry Andric
1728*b5893f02SDimitry Andricinline constexpr
1729*b5893f02SDimitry Andricmonth operator- (const month& __lhs, const months& __rhs) noexcept
1730*b5893f02SDimitry Andric{ return __lhs + -__rhs; }
1731*b5893f02SDimitry Andric
1732*b5893f02SDimitry Andricinline constexpr
1733*b5893f02SDimitry Andricmonths operator-(const month& __lhs, const month& __rhs) noexcept
1734*b5893f02SDimitry Andric{
1735*b5893f02SDimitry Andric    auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
1736*b5893f02SDimitry Andric    return months(__dm <= 11 ? __dm : __dm + 12);
1737*b5893f02SDimitry Andric}
1738*b5893f02SDimitry Andric
1739*b5893f02SDimitry Andricinline constexpr month& month::operator+=(const months& __dm) noexcept
1740*b5893f02SDimitry Andric{ *this = *this + __dm; return *this; }
1741*b5893f02SDimitry Andric
1742*b5893f02SDimitry Andricinline constexpr month& month::operator-=(const months& __dm) noexcept
1743*b5893f02SDimitry Andric{ *this = *this - __dm; return *this; }
1744*b5893f02SDimitry Andric
1745*b5893f02SDimitry Andric
1746*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS year {
1747*b5893f02SDimitry Andricprivate:
1748*b5893f02SDimitry Andric    short __y;
1749*b5893f02SDimitry Andricpublic:
1750*b5893f02SDimitry Andric    year() = default;
1751*b5893f02SDimitry Andric    explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
1752*b5893f02SDimitry Andric
1753*b5893f02SDimitry Andric    inline constexpr year& operator++()    noexcept { ++__y; return *this; };
1754*b5893f02SDimitry Andric    inline constexpr year  operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; };
1755*b5893f02SDimitry Andric    inline constexpr year& operator--()    noexcept { --__y; return *this; };
1756*b5893f02SDimitry Andric    inline constexpr year  operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; };
1757*b5893f02SDimitry Andric           constexpr year& operator+=(const years& __dy) noexcept;
1758*b5893f02SDimitry Andric           constexpr year& operator-=(const years& __dy) noexcept;
1759*b5893f02SDimitry Andric    inline constexpr year operator+() const noexcept { return *this; }
1760*b5893f02SDimitry Andric    inline constexpr year operator-() const noexcept { return year{-__y}; };
1761*b5893f02SDimitry Andric
1762*b5893f02SDimitry Andric    inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
1763*b5893f02SDimitry Andric    explicit inline constexpr operator int() const noexcept { return __y; }
1764*b5893f02SDimitry Andric           constexpr bool ok() const noexcept;
1765*b5893f02SDimitry Andric    static inline constexpr year min() noexcept { return year{-32767}; }
1766*b5893f02SDimitry Andric    static inline constexpr year max() noexcept { return year{ 32767}; }
1767*b5893f02SDimitry Andric};
1768*b5893f02SDimitry Andric
1769*b5893f02SDimitry Andric
1770*b5893f02SDimitry Andricinline constexpr
1771*b5893f02SDimitry Andricbool operator==(const year& __lhs, const year& __rhs) noexcept
1772*b5893f02SDimitry Andric{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
1773*b5893f02SDimitry Andric
1774*b5893f02SDimitry Andricinline constexpr
1775*b5893f02SDimitry Andricbool operator!=(const year& __lhs, const year& __rhs) noexcept
1776*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
1777*b5893f02SDimitry Andric
1778*b5893f02SDimitry Andricinline constexpr
1779*b5893f02SDimitry Andricbool operator< (const year& __lhs, const year& __rhs) noexcept
1780*b5893f02SDimitry Andric{ return static_cast<int>(__lhs)  < static_cast<int>(__rhs); }
1781*b5893f02SDimitry Andric
1782*b5893f02SDimitry Andricinline constexpr
1783*b5893f02SDimitry Andricbool operator> (const year& __lhs, const year& __rhs) noexcept
1784*b5893f02SDimitry Andric{ return __rhs < __lhs; }
1785*b5893f02SDimitry Andric
1786*b5893f02SDimitry Andricinline constexpr
1787*b5893f02SDimitry Andricbool operator<=(const year& __lhs, const year& __rhs) noexcept
1788*b5893f02SDimitry Andric{ return !(__rhs < __lhs); }
1789*b5893f02SDimitry Andric
1790*b5893f02SDimitry Andricinline constexpr
1791*b5893f02SDimitry Andricbool operator>=(const year& __lhs, const year& __rhs) noexcept
1792*b5893f02SDimitry Andric{ return !(__lhs < __rhs); }
1793*b5893f02SDimitry Andric
1794*b5893f02SDimitry Andricinline constexpr
1795*b5893f02SDimitry Andricyear operator+ (const year& __lhs, const years& __rhs) noexcept
1796*b5893f02SDimitry Andric{ return year(static_cast<int>(__lhs) + __rhs.count()); }
1797*b5893f02SDimitry Andric
1798*b5893f02SDimitry Andricinline constexpr
1799*b5893f02SDimitry Andricyear operator+ (const years& __lhs, const year& __rhs) noexcept
1800*b5893f02SDimitry Andric{ return __rhs + __lhs; }
1801*b5893f02SDimitry Andric
1802*b5893f02SDimitry Andricinline constexpr
1803*b5893f02SDimitry Andricyear operator- (const year& __lhs, const years& __rhs) noexcept
1804*b5893f02SDimitry Andric{ return __lhs + -__rhs; }
1805*b5893f02SDimitry Andric
1806*b5893f02SDimitry Andricinline constexpr
1807*b5893f02SDimitry Andricyears operator-(const year& __lhs, const year& __rhs) noexcept
1808*b5893f02SDimitry Andric{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
1809*b5893f02SDimitry Andric
1810*b5893f02SDimitry Andric
1811*b5893f02SDimitry Andricinline constexpr year& year::operator+=(const years& __dy) noexcept
1812*b5893f02SDimitry Andric{ *this = *this + __dy; return *this; }
1813*b5893f02SDimitry Andric
1814*b5893f02SDimitry Andricinline constexpr year& year::operator-=(const years& __dy) noexcept
1815*b5893f02SDimitry Andric{ *this = *this - __dy; return *this; }
1816*b5893f02SDimitry Andric
1817*b5893f02SDimitry Andricinline constexpr bool year::ok() const noexcept
1818*b5893f02SDimitry Andric{ return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); }
1819*b5893f02SDimitry Andric
1820*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS weekday_indexed;
1821*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS weekday_last;
1822*b5893f02SDimitry Andric
1823*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS weekday {
1824*b5893f02SDimitry Andricprivate:
1825*b5893f02SDimitry Andric    unsigned char __wd;
1826*b5893f02SDimitry Andricpublic:
1827*b5893f02SDimitry Andric  weekday() = default;
1828*b5893f02SDimitry Andric  inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val)) {}
1829*b5893f02SDimitry Andric  inline constexpr          weekday(const sys_days& __sysd) noexcept
1830*b5893f02SDimitry Andric          : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
1831*b5893f02SDimitry Andric  inline explicit constexpr weekday(const local_days& __locd) noexcept
1832*b5893f02SDimitry Andric          : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
1833*b5893f02SDimitry Andric
1834*b5893f02SDimitry Andric  inline constexpr weekday& operator++()    noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
1835*b5893f02SDimitry Andric  inline constexpr weekday  operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
1836*b5893f02SDimitry Andric  inline constexpr weekday& operator--()    noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
1837*b5893f02SDimitry Andric  inline constexpr weekday  operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
1838*b5893f02SDimitry Andric         constexpr weekday& operator+=(const days& __dd) noexcept;
1839*b5893f02SDimitry Andric         constexpr weekday& operator-=(const days& __dd) noexcept;
1840*b5893f02SDimitry Andric  inline explicit constexpr operator unsigned() const noexcept { return __wd; }
1841*b5893f02SDimitry Andric  inline constexpr bool ok() const noexcept { return __wd <= 6; }
1842*b5893f02SDimitry Andric         constexpr weekday_indexed operator[](unsigned __index) const noexcept;
1843*b5893f02SDimitry Andric         constexpr weekday_last    operator[](last_spec) const noexcept;
1844*b5893f02SDimitry Andric
1845*b5893f02SDimitry Andric  static constexpr unsigned char __weekday_from_days(int __days) noexcept;
1846*b5893f02SDimitry Andric};
1847*b5893f02SDimitry Andric
1848*b5893f02SDimitry Andric
1849*b5893f02SDimitry Andric// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
1850*b5893f02SDimitry Andricinline constexpr
1851*b5893f02SDimitry Andricunsigned char weekday::__weekday_from_days(int __days) noexcept
1852*b5893f02SDimitry Andric{
1853*b5893f02SDimitry Andric    return static_cast<unsigned char>(
1854*b5893f02SDimitry Andric              static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
1855*b5893f02SDimitry Andric           );
1856*b5893f02SDimitry Andric}
1857*b5893f02SDimitry Andric
1858*b5893f02SDimitry Andricinline constexpr
1859*b5893f02SDimitry Andricbool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
1860*b5893f02SDimitry Andric{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
1861*b5893f02SDimitry Andric
1862*b5893f02SDimitry Andricinline constexpr
1863*b5893f02SDimitry Andricbool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
1864*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
1865*b5893f02SDimitry Andric
1866*b5893f02SDimitry Andricinline constexpr
1867*b5893f02SDimitry Andricbool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
1868*b5893f02SDimitry Andric{ return static_cast<unsigned>(__lhs) <  static_cast<unsigned>(__rhs); }
1869*b5893f02SDimitry Andric
1870*b5893f02SDimitry Andricinline constexpr
1871*b5893f02SDimitry Andricbool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
1872*b5893f02SDimitry Andric{ return __rhs < __lhs; }
1873*b5893f02SDimitry Andric
1874*b5893f02SDimitry Andricinline constexpr
1875*b5893f02SDimitry Andricbool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
1876*b5893f02SDimitry Andric{ return !(__rhs < __lhs);}
1877*b5893f02SDimitry Andric
1878*b5893f02SDimitry Andricinline constexpr
1879*b5893f02SDimitry Andricbool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
1880*b5893f02SDimitry Andric{ return !(__lhs < __rhs); }
1881*b5893f02SDimitry Andric
1882*b5893f02SDimitry Andricconstexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
1883*b5893f02SDimitry Andric{
1884*b5893f02SDimitry Andric    auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + __rhs.count();
1885*b5893f02SDimitry Andric    auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
1886*b5893f02SDimitry Andric    return weekday{static_cast<unsigned>(__mu - __yr * 7)};
1887*b5893f02SDimitry Andric}
1888*b5893f02SDimitry Andric
1889*b5893f02SDimitry Andricconstexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
1890*b5893f02SDimitry Andric{ return __rhs + __lhs; }
1891*b5893f02SDimitry Andric
1892*b5893f02SDimitry Andricconstexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
1893*b5893f02SDimitry Andric{ return __lhs + -__rhs; }
1894*b5893f02SDimitry Andric
1895*b5893f02SDimitry Andricconstexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
1896*b5893f02SDimitry Andric{
1897*b5893f02SDimitry Andric    const int __wdu = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
1898*b5893f02SDimitry Andric    const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
1899*b5893f02SDimitry Andric    return days{__wdu - __wk * 7};
1900*b5893f02SDimitry Andric}
1901*b5893f02SDimitry Andric
1902*b5893f02SDimitry Andricinline constexpr weekday& weekday::operator+=(const days& __dd) noexcept
1903*b5893f02SDimitry Andric{ *this = *this + __dd; return *this; }
1904*b5893f02SDimitry Andric
1905*b5893f02SDimitry Andricinline constexpr weekday& weekday::operator-=(const days& __dd) noexcept
1906*b5893f02SDimitry Andric{ *this = *this - __dd; return *this; }
1907*b5893f02SDimitry Andric
1908*b5893f02SDimitry Andric
1909*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS weekday_indexed {
1910*b5893f02SDimitry Andricprivate:
1911*b5893f02SDimitry Andric    _VSTD::chrono::weekday __wd;
1912*b5893f02SDimitry Andric    unsigned char          __idx;
1913*b5893f02SDimitry Andricpublic:
1914*b5893f02SDimitry Andric    weekday_indexed() = default;
1915*b5893f02SDimitry Andric    inline constexpr weekday_indexed(const _VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept
1916*b5893f02SDimitry Andric        : __wd{__wdval}, __idx(__idxval) {}
1917*b5893f02SDimitry Andric    inline constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
1918*b5893f02SDimitry Andric    inline constexpr unsigned                 index() const noexcept { return __idx; }
1919*b5893f02SDimitry Andric    inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
1920*b5893f02SDimitry Andric};
1921*b5893f02SDimitry Andric
1922*b5893f02SDimitry Andricinline constexpr
1923*b5893f02SDimitry Andricbool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
1924*b5893f02SDimitry Andric{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
1925*b5893f02SDimitry Andric
1926*b5893f02SDimitry Andricinline constexpr
1927*b5893f02SDimitry Andricbool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
1928*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
1929*b5893f02SDimitry Andric
1930*b5893f02SDimitry Andric
1931*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS weekday_last {
1932*b5893f02SDimitry Andricprivate:
1933*b5893f02SDimitry Andric    _VSTD::chrono::weekday __wd;
1934*b5893f02SDimitry Andricpublic:
1935*b5893f02SDimitry Andric    explicit constexpr weekday_last(const _VSTD::chrono::weekday& __val) noexcept
1936*b5893f02SDimitry Andric        : __wd{__val} {}
1937*b5893f02SDimitry Andric    constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
1938*b5893f02SDimitry Andric    constexpr bool ok() const noexcept { return __wd.ok(); }
1939*b5893f02SDimitry Andric};
1940*b5893f02SDimitry Andric
1941*b5893f02SDimitry Andricinline constexpr
1942*b5893f02SDimitry Andricbool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
1943*b5893f02SDimitry Andric{ return __lhs.weekday() == __rhs.weekday(); }
1944*b5893f02SDimitry Andric
1945*b5893f02SDimitry Andricinline constexpr
1946*b5893f02SDimitry Andricbool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
1947*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
1948*b5893f02SDimitry Andric
1949*b5893f02SDimitry Andricinline constexpr
1950*b5893f02SDimitry Andricweekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
1951*b5893f02SDimitry Andric
1952*b5893f02SDimitry Andricinline constexpr
1953*b5893f02SDimitry Andricweekday_last    weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
1954*b5893f02SDimitry Andric
1955*b5893f02SDimitry Andric
1956*b5893f02SDimitry Andricinline constexpr last_spec last{};
1957*b5893f02SDimitry Andricinline constexpr weekday   Sunday{0};
1958*b5893f02SDimitry Andricinline constexpr weekday   Monday{1};
1959*b5893f02SDimitry Andricinline constexpr weekday   Tuesday{2};
1960*b5893f02SDimitry Andricinline constexpr weekday   Wednesday{3};
1961*b5893f02SDimitry Andricinline constexpr weekday   Thursday{4};
1962*b5893f02SDimitry Andricinline constexpr weekday   Friday{5};
1963*b5893f02SDimitry Andricinline constexpr weekday   Saturday{6};
1964*b5893f02SDimitry Andric
1965*b5893f02SDimitry Andricinline constexpr month January{1};
1966*b5893f02SDimitry Andricinline constexpr month February{2};
1967*b5893f02SDimitry Andricinline constexpr month March{3};
1968*b5893f02SDimitry Andricinline constexpr month April{4};
1969*b5893f02SDimitry Andricinline constexpr month May{5};
1970*b5893f02SDimitry Andricinline constexpr month June{6};
1971*b5893f02SDimitry Andricinline constexpr month July{7};
1972*b5893f02SDimitry Andricinline constexpr month August{8};
1973*b5893f02SDimitry Andricinline constexpr month September{9};
1974*b5893f02SDimitry Andricinline constexpr month October{10};
1975*b5893f02SDimitry Andricinline constexpr month November{11};
1976*b5893f02SDimitry Andricinline constexpr month December{12};
1977*b5893f02SDimitry Andric
1978*b5893f02SDimitry Andric
1979*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS month_day {
1980*b5893f02SDimitry Andricprivate:
1981*b5893f02SDimitry Andric   chrono::month __m;
1982*b5893f02SDimitry Andric   chrono::day   __d;
1983*b5893f02SDimitry Andricpublic:
1984*b5893f02SDimitry Andric    month_day() = default;
1985*b5893f02SDimitry Andric    constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
1986*b5893f02SDimitry Andric        : __m{__mval}, __d{__dval} {}
1987*b5893f02SDimitry Andric    inline constexpr chrono::month month() const noexcept { return __m; }
1988*b5893f02SDimitry Andric    inline constexpr chrono::day   day()   const noexcept { return __d; }
1989*b5893f02SDimitry Andric    constexpr bool ok() const noexcept;
1990*b5893f02SDimitry Andric};
1991*b5893f02SDimitry Andric
1992*b5893f02SDimitry Andricinline constexpr
1993*b5893f02SDimitry Andricbool month_day::ok() const noexcept
1994*b5893f02SDimitry Andric{
1995*b5893f02SDimitry Andric    if (!__m.ok()) return false;
1996*b5893f02SDimitry Andric    const unsigned __dval = static_cast<unsigned>(__d);
1997*b5893f02SDimitry Andric    if (__dval < 1 || __dval > 31) return false;
1998*b5893f02SDimitry Andric    if (__dval <= 29) return true;
1999*b5893f02SDimitry Andric//  Now we've got either 30 or 31
2000*b5893f02SDimitry Andric    const unsigned __mval = static_cast<unsigned>(__m);
2001*b5893f02SDimitry Andric    if (__mval == 2) return false;
2002*b5893f02SDimitry Andric    if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
2003*b5893f02SDimitry Andric        return __dval == 30;
2004*b5893f02SDimitry Andric    return true;
2005*b5893f02SDimitry Andric}
2006*b5893f02SDimitry Andric
2007*b5893f02SDimitry Andricinline constexpr
2008*b5893f02SDimitry Andricbool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
2009*b5893f02SDimitry Andric{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
2010*b5893f02SDimitry Andric
2011*b5893f02SDimitry Andricinline constexpr
2012*b5893f02SDimitry Andricbool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
2013*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
2014*b5893f02SDimitry Andric
2015*b5893f02SDimitry Andricinline constexpr
2016*b5893f02SDimitry Andricmonth_day operator/(const month& __lhs, const day& __rhs) noexcept
2017*b5893f02SDimitry Andric{ return month_day{__lhs, __rhs}; }
2018*b5893f02SDimitry Andric
2019*b5893f02SDimitry Andricconstexpr
2020*b5893f02SDimitry Andricmonth_day operator/(const day& __lhs, const month& __rhs) noexcept
2021*b5893f02SDimitry Andric{ return __rhs / __lhs; }
2022*b5893f02SDimitry Andric
2023*b5893f02SDimitry Andricinline constexpr
2024*b5893f02SDimitry Andricmonth_day operator/(const month& __lhs, int __rhs) noexcept
2025*b5893f02SDimitry Andric{ return __lhs / day(__rhs); }
2026*b5893f02SDimitry Andric
2027*b5893f02SDimitry Andricconstexpr
2028*b5893f02SDimitry Andricmonth_day operator/(int __lhs, const day& __rhs) noexcept
2029*b5893f02SDimitry Andric{ return month(__lhs) / __rhs; }
2030*b5893f02SDimitry Andric
2031*b5893f02SDimitry Andricconstexpr
2032*b5893f02SDimitry Andricmonth_day operator/(const day& __lhs, int __rhs) noexcept
2033*b5893f02SDimitry Andric{ return month(__rhs) / __lhs; }
2034*b5893f02SDimitry Andric
2035*b5893f02SDimitry Andric
2036*b5893f02SDimitry Andricinline constexpr
2037*b5893f02SDimitry Andricbool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
2038*b5893f02SDimitry Andric{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
2039*b5893f02SDimitry Andric
2040*b5893f02SDimitry Andricinline constexpr
2041*b5893f02SDimitry Andricbool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
2042*b5893f02SDimitry Andric{ return __rhs < __lhs; }
2043*b5893f02SDimitry Andric
2044*b5893f02SDimitry Andricinline constexpr
2045*b5893f02SDimitry Andricbool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
2046*b5893f02SDimitry Andric{ return !(__rhs < __lhs);}
2047*b5893f02SDimitry Andric
2048*b5893f02SDimitry Andricinline constexpr
2049*b5893f02SDimitry Andricbool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
2050*b5893f02SDimitry Andric{ return !(__lhs < __rhs); }
2051*b5893f02SDimitry Andric
2052*b5893f02SDimitry Andric
2053*b5893f02SDimitry Andric
2054*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS month_day_last {
2055*b5893f02SDimitry Andricprivate:
2056*b5893f02SDimitry Andric    chrono::month __m;
2057*b5893f02SDimitry Andricpublic:
2058*b5893f02SDimitry Andric    explicit constexpr month_day_last(const chrono::month& __val) noexcept
2059*b5893f02SDimitry Andric        : __m{__val} {}
2060*b5893f02SDimitry Andric    inline constexpr chrono::month month() const noexcept { return __m; }
2061*b5893f02SDimitry Andric    inline constexpr bool ok() const noexcept { return __m.ok(); }
2062*b5893f02SDimitry Andric};
2063*b5893f02SDimitry Andric
2064*b5893f02SDimitry Andricinline constexpr
2065*b5893f02SDimitry Andricbool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2066*b5893f02SDimitry Andric{ return __lhs.month() == __rhs.month(); }
2067*b5893f02SDimitry Andric
2068*b5893f02SDimitry Andricinline constexpr
2069*b5893f02SDimitry Andricbool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2070*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
2071*b5893f02SDimitry Andric
2072*b5893f02SDimitry Andricinline constexpr
2073*b5893f02SDimitry Andricbool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2074*b5893f02SDimitry Andric{ return __lhs.month() < __rhs.month(); }
2075*b5893f02SDimitry Andric
2076*b5893f02SDimitry Andricinline constexpr
2077*b5893f02SDimitry Andricbool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2078*b5893f02SDimitry Andric{ return __rhs < __lhs; }
2079*b5893f02SDimitry Andric
2080*b5893f02SDimitry Andricinline constexpr
2081*b5893f02SDimitry Andricbool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2082*b5893f02SDimitry Andric{ return !(__rhs < __lhs);}
2083*b5893f02SDimitry Andric
2084*b5893f02SDimitry Andricinline constexpr
2085*b5893f02SDimitry Andricbool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
2086*b5893f02SDimitry Andric{ return !(__lhs < __rhs); }
2087*b5893f02SDimitry Andric
2088*b5893f02SDimitry Andricinline constexpr
2089*b5893f02SDimitry Andricmonth_day_last operator/(const month& __lhs, last_spec) noexcept
2090*b5893f02SDimitry Andric{ return month_day_last{__lhs}; }
2091*b5893f02SDimitry Andric
2092*b5893f02SDimitry Andricinline constexpr
2093*b5893f02SDimitry Andricmonth_day_last operator/(last_spec, const month& __rhs) noexcept
2094*b5893f02SDimitry Andric{ return month_day_last{__rhs}; }
2095*b5893f02SDimitry Andric
2096*b5893f02SDimitry Andricinline constexpr
2097*b5893f02SDimitry Andricmonth_day_last operator/(int __lhs, last_spec) noexcept
2098*b5893f02SDimitry Andric{ return month_day_last{month(__lhs)}; }
2099*b5893f02SDimitry Andric
2100*b5893f02SDimitry Andricinline constexpr
2101*b5893f02SDimitry Andricmonth_day_last operator/(last_spec, int __rhs) noexcept
2102*b5893f02SDimitry Andric{ return month_day_last{month(__rhs)}; }
2103*b5893f02SDimitry Andric
2104*b5893f02SDimitry Andric
2105*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS month_weekday {
2106*b5893f02SDimitry Andricprivate:
2107*b5893f02SDimitry Andric    chrono::month __m;
2108*b5893f02SDimitry Andric    chrono::weekday_indexed __wdi;
2109*b5893f02SDimitry Andricpublic:
2110*b5893f02SDimitry Andric    month_weekday() = default;
2111*b5893f02SDimitry Andric    constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
2112*b5893f02SDimitry Andric        : __m{__mval}, __wdi{__wdival} {}
2113*b5893f02SDimitry Andric    inline constexpr chrono::month                     month() const noexcept { return __m; }
2114*b5893f02SDimitry Andric    inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
2115*b5893f02SDimitry Andric    inline constexpr bool                                 ok() const noexcept { return __m.ok() && __wdi.ok(); }
2116*b5893f02SDimitry Andric};
2117*b5893f02SDimitry Andric
2118*b5893f02SDimitry Andricinline constexpr
2119*b5893f02SDimitry Andricbool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
2120*b5893f02SDimitry Andric{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
2121*b5893f02SDimitry Andric
2122*b5893f02SDimitry Andricinline constexpr
2123*b5893f02SDimitry Andricbool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
2124*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
2125*b5893f02SDimitry Andric
2126*b5893f02SDimitry Andricinline constexpr
2127*b5893f02SDimitry Andricmonth_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
2128*b5893f02SDimitry Andric{ return month_weekday{__lhs, __rhs}; }
2129*b5893f02SDimitry Andric
2130*b5893f02SDimitry Andricinline constexpr
2131*b5893f02SDimitry Andricmonth_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
2132*b5893f02SDimitry Andric{ return month_weekday{month(__lhs), __rhs}; }
2133*b5893f02SDimitry Andric
2134*b5893f02SDimitry Andricinline constexpr
2135*b5893f02SDimitry Andricmonth_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
2136*b5893f02SDimitry Andric{ return month_weekday{__rhs, __lhs}; }
2137*b5893f02SDimitry Andric
2138*b5893f02SDimitry Andricinline constexpr
2139*b5893f02SDimitry Andricmonth_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
2140*b5893f02SDimitry Andric{ return month_weekday{month(__rhs), __lhs}; }
2141*b5893f02SDimitry Andric
2142*b5893f02SDimitry Andric
2143*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS month_weekday_last {
2144*b5893f02SDimitry Andric    chrono::month        __m;
2145*b5893f02SDimitry Andric    chrono::weekday_last __wdl;
2146*b5893f02SDimitry Andric  public:
2147*b5893f02SDimitry Andric    constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
2148*b5893f02SDimitry Andric        : __m{__mval}, __wdl{__wdlval} {}
2149*b5893f02SDimitry Andric    inline constexpr chrono::month               month() const noexcept { return __m; }
2150*b5893f02SDimitry Andric    inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
2151*b5893f02SDimitry Andric    inline constexpr bool                           ok() const noexcept { return __m.ok() && __wdl.ok(); }
2152*b5893f02SDimitry Andric};
2153*b5893f02SDimitry Andric
2154*b5893f02SDimitry Andricinline constexpr
2155*b5893f02SDimitry Andricbool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
2156*b5893f02SDimitry Andric{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
2157*b5893f02SDimitry Andric
2158*b5893f02SDimitry Andricinline constexpr
2159*b5893f02SDimitry Andricbool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
2160*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
2161*b5893f02SDimitry Andric
2162*b5893f02SDimitry Andric
2163*b5893f02SDimitry Andricinline constexpr
2164*b5893f02SDimitry Andricmonth_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
2165*b5893f02SDimitry Andric{ return month_weekday_last{__lhs, __rhs}; }
2166*b5893f02SDimitry Andric
2167*b5893f02SDimitry Andricinline constexpr
2168*b5893f02SDimitry Andricmonth_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
2169*b5893f02SDimitry Andric{ return month_weekday_last{month(__lhs), __rhs}; }
2170*b5893f02SDimitry Andric
2171*b5893f02SDimitry Andricinline constexpr
2172*b5893f02SDimitry Andricmonth_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
2173*b5893f02SDimitry Andric{ return month_weekday_last{__rhs, __lhs}; }
2174*b5893f02SDimitry Andric
2175*b5893f02SDimitry Andricinline constexpr
2176*b5893f02SDimitry Andricmonth_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
2177*b5893f02SDimitry Andric{ return month_weekday_last{month(__rhs), __lhs}; }
2178*b5893f02SDimitry Andric
2179*b5893f02SDimitry Andric
2180*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS year_month {
2181*b5893f02SDimitry Andric    chrono::year  __y;
2182*b5893f02SDimitry Andric    chrono::month __m;
2183*b5893f02SDimitry Andricpublic:
2184*b5893f02SDimitry Andric    year_month() = default;
2185*b5893f02SDimitry Andric    constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
2186*b5893f02SDimitry Andric        : __y{__yval}, __m{__mval} {}
2187*b5893f02SDimitry Andric    inline constexpr chrono::year  year()  const noexcept { return __y; }
2188*b5893f02SDimitry Andric    inline constexpr chrono::month month() const noexcept { return __m; }
2189*b5893f02SDimitry Andric    inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
2190*b5893f02SDimitry Andric    inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
2191*b5893f02SDimitry Andric    inline constexpr year_month& operator+=(const years& __dy)  noexcept { this->__y += __dy; return *this; }
2192*b5893f02SDimitry Andric    inline constexpr year_month& operator-=(const years& __dy)  noexcept { this->__y -= __dy; return *this; }
2193*b5893f02SDimitry Andric    inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
2194*b5893f02SDimitry Andric};
2195*b5893f02SDimitry Andric
2196*b5893f02SDimitry Andricinline constexpr
2197*b5893f02SDimitry Andricyear_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
2198*b5893f02SDimitry Andric
2199*b5893f02SDimitry Andricinline constexpr
2200*b5893f02SDimitry Andricyear_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
2201*b5893f02SDimitry Andric
2202*b5893f02SDimitry Andricinline constexpr
2203*b5893f02SDimitry Andricbool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
2204*b5893f02SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
2205*b5893f02SDimitry Andric
2206*b5893f02SDimitry Andricinline constexpr
2207*b5893f02SDimitry Andricbool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
2208*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
2209*b5893f02SDimitry Andric
2210*b5893f02SDimitry Andricinline constexpr
2211*b5893f02SDimitry Andricbool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
2212*b5893f02SDimitry Andric{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
2213*b5893f02SDimitry Andric
2214*b5893f02SDimitry Andricinline constexpr
2215*b5893f02SDimitry Andricbool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
2216*b5893f02SDimitry Andric{ return __rhs < __lhs; }
2217*b5893f02SDimitry Andric
2218*b5893f02SDimitry Andricinline constexpr
2219*b5893f02SDimitry Andricbool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
2220*b5893f02SDimitry Andric{ return !(__rhs < __lhs);}
2221*b5893f02SDimitry Andric
2222*b5893f02SDimitry Andricinline constexpr
2223*b5893f02SDimitry Andricbool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
2224*b5893f02SDimitry Andric{ return !(__lhs < __rhs); }
2225*b5893f02SDimitry Andric
2226*b5893f02SDimitry Andricconstexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
2227*b5893f02SDimitry Andric{
2228*b5893f02SDimitry Andric    int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
2229*b5893f02SDimitry Andric    const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
2230*b5893f02SDimitry Andric    __dmi = __dmi - __dy * 12 + 1;
2231*b5893f02SDimitry Andric    return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
2232*b5893f02SDimitry Andric}
2233*b5893f02SDimitry Andric
2234*b5893f02SDimitry Andricconstexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
2235*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2236*b5893f02SDimitry Andric
2237*b5893f02SDimitry Andricconstexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
2238*b5893f02SDimitry Andric{ return (__lhs.year() + __rhs) / __lhs.month(); }
2239*b5893f02SDimitry Andric
2240*b5893f02SDimitry Andricconstexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
2241*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2242*b5893f02SDimitry Andric
2243*b5893f02SDimitry Andricconstexpr months     operator-(const year_month& __lhs, const year_month& __rhs) noexcept
2244*b5893f02SDimitry Andric{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
2245*b5893f02SDimitry Andric
2246*b5893f02SDimitry Andricconstexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
2247*b5893f02SDimitry Andric{ return __lhs + -__rhs; }
2248*b5893f02SDimitry Andric
2249*b5893f02SDimitry Andricconstexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
2250*b5893f02SDimitry Andric{ return __lhs + -__rhs; }
2251*b5893f02SDimitry Andric
2252*b5893f02SDimitry Andricclass year_month_day_last;
2253*b5893f02SDimitry Andric
2254*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS year_month_day {
2255*b5893f02SDimitry Andricprivate:
2256*b5893f02SDimitry Andric    chrono::year  __y;
2257*b5893f02SDimitry Andric    chrono::month __m;
2258*b5893f02SDimitry Andric    chrono::day   __d;
2259*b5893f02SDimitry Andricpublic:
2260*b5893f02SDimitry Andric     year_month_day() = default;
2261*b5893f02SDimitry Andric     inline constexpr year_month_day(
2262*b5893f02SDimitry Andric            const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
2263*b5893f02SDimitry Andric            : __y{__yval}, __m{__mval}, __d{__dval} {}
2264*b5893f02SDimitry Andric            constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
2265*b5893f02SDimitry Andric     inline constexpr year_month_day(const sys_days& __sysd) noexcept
2266*b5893f02SDimitry Andric            : year_month_day(__from_days(__sysd.time_since_epoch())) {}
2267*b5893f02SDimitry Andric     inline explicit constexpr year_month_day(const local_days& __locd) noexcept
2268*b5893f02SDimitry Andric            : year_month_day(__from_days(__locd.time_since_epoch())) {}
2269*b5893f02SDimitry Andric
2270*b5893f02SDimitry Andric            constexpr year_month_day& operator+=(const months& __dm) noexcept;
2271*b5893f02SDimitry Andric            constexpr year_month_day& operator-=(const months& __dm) noexcept;
2272*b5893f02SDimitry Andric            constexpr year_month_day& operator+=(const years& __dy)  noexcept;
2273*b5893f02SDimitry Andric            constexpr year_month_day& operator-=(const years& __dy)  noexcept;
2274*b5893f02SDimitry Andric
2275*b5893f02SDimitry Andric     inline constexpr chrono::year   year() const noexcept { return __y; }
2276*b5893f02SDimitry Andric     inline constexpr chrono::month month() const noexcept { return __m; }
2277*b5893f02SDimitry Andric     inline constexpr chrono::day     day() const noexcept { return __d; }
2278*b5893f02SDimitry Andric     inline constexpr operator   sys_days() const noexcept          { return   sys_days{__to_days()}; }
2279*b5893f02SDimitry Andric     inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
2280*b5893f02SDimitry Andric
2281*b5893f02SDimitry Andric            constexpr bool             ok() const noexcept;
2282*b5893f02SDimitry Andric
2283*b5893f02SDimitry Andric     static constexpr year_month_day __from_days(days __d) noexcept;
2284*b5893f02SDimitry Andric     constexpr days __to_days() const noexcept;
2285*b5893f02SDimitry Andric};
2286*b5893f02SDimitry Andric
2287*b5893f02SDimitry Andric
2288*b5893f02SDimitry Andric// https://howardhinnant.github.io/date_algorithms.html#civil_from_days
2289*b5893f02SDimitry Andricinline constexpr
2290*b5893f02SDimitry Andricyear_month_day
2291*b5893f02SDimitry Andricyear_month_day::__from_days(days __d) noexcept
2292*b5893f02SDimitry Andric{
2293*b5893f02SDimitry Andric    static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
2294*b5893f02SDimitry Andric    static_assert(std::numeric_limits<int>::digits >= 20     , "");
2295*b5893f02SDimitry Andric    const int      __z = __d.count() + 719468;
2296*b5893f02SDimitry Andric    const int      __era = (__z >= 0 ? __z : __z - 146096) / 146097;
2297*b5893f02SDimitry Andric    const unsigned __doe = static_cast<unsigned>(__z - __era * 146097);              // [0, 146096]
2298*b5893f02SDimitry Andric    const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365;  // [0, 399]
2299*b5893f02SDimitry Andric    const int      __yr = static_cast<int>(__yoe) + __era * 400;
2300*b5893f02SDimitry Andric    const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100);              // [0, 365]
2301*b5893f02SDimitry Andric    const unsigned __mp = (5 * __doy + 2)/153;                                       // [0, 11]
2302*b5893f02SDimitry Andric    const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1;                            // [1, 31]
2303*b5893f02SDimitry Andric    const unsigned __mth = __mp + (__mp < 10 ? 3 : -9);                              // [1, 12]
2304*b5893f02SDimitry Andric    return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
2305*b5893f02SDimitry Andric}
2306*b5893f02SDimitry Andric
2307*b5893f02SDimitry Andric// https://howardhinnant.github.io/date_algorithms.html#days_from_civil
2308*b5893f02SDimitry Andricinline constexpr days year_month_day::__to_days() const noexcept
2309*b5893f02SDimitry Andric{
2310*b5893f02SDimitry Andric    static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
2311*b5893f02SDimitry Andric    static_assert(std::numeric_limits<int>::digits >= 20     , "");
2312*b5893f02SDimitry Andric
2313*b5893f02SDimitry Andric    const int      __yr  = static_cast<int>(__y) - (__m <= February);
2314*b5893f02SDimitry Andric    const unsigned __mth = static_cast<unsigned>(__m);
2315*b5893f02SDimitry Andric    const unsigned __dy  = static_cast<unsigned>(__d);
2316*b5893f02SDimitry Andric
2317*b5893f02SDimitry Andric    const int      __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
2318*b5893f02SDimitry Andric    const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400);                // [0, 399]
2319*b5893f02SDimitry Andric    const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1;  // [0, 365]
2320*b5893f02SDimitry Andric    const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy;                // [0, 146096]
2321*b5893f02SDimitry Andric    return days{__era * 146097 + static_cast<int>(__doe) - 719468};
2322*b5893f02SDimitry Andric}
2323*b5893f02SDimitry Andric
2324*b5893f02SDimitry Andricinline constexpr
2325*b5893f02SDimitry Andricbool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2326*b5893f02SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
2327*b5893f02SDimitry Andric
2328*b5893f02SDimitry Andricinline constexpr
2329*b5893f02SDimitry Andricbool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2330*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
2331*b5893f02SDimitry Andric
2332*b5893f02SDimitry Andricinline constexpr
2333*b5893f02SDimitry Andricbool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2334*b5893f02SDimitry Andric{
2335*b5893f02SDimitry Andric    if (__lhs.year() < __rhs.year()) return true;
2336*b5893f02SDimitry Andric    if (__lhs.year() > __rhs.year()) return false;
2337*b5893f02SDimitry Andric    if (__lhs.month() < __rhs.month()) return true;
2338*b5893f02SDimitry Andric    if (__lhs.month() > __rhs.month()) return false;
2339*b5893f02SDimitry Andric    return __lhs.day() < __rhs.day();
2340*b5893f02SDimitry Andric}
2341*b5893f02SDimitry Andric
2342*b5893f02SDimitry Andricinline constexpr
2343*b5893f02SDimitry Andricbool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2344*b5893f02SDimitry Andric{ return __rhs < __lhs; }
2345*b5893f02SDimitry Andric
2346*b5893f02SDimitry Andricinline constexpr
2347*b5893f02SDimitry Andricbool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2348*b5893f02SDimitry Andric{ return !(__rhs < __lhs);}
2349*b5893f02SDimitry Andric
2350*b5893f02SDimitry Andricinline constexpr
2351*b5893f02SDimitry Andricbool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
2352*b5893f02SDimitry Andric{ return !(__lhs < __rhs); }
2353*b5893f02SDimitry Andric
2354*b5893f02SDimitry Andricinline constexpr
2355*b5893f02SDimitry Andricyear_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
2356*b5893f02SDimitry Andric{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
2357*b5893f02SDimitry Andric
2358*b5893f02SDimitry Andricinline constexpr
2359*b5893f02SDimitry Andricyear_month_day operator/(const year_month& __lhs, int __rhs) noexcept
2360*b5893f02SDimitry Andric{ return __lhs / day(__rhs); }
2361*b5893f02SDimitry Andric
2362*b5893f02SDimitry Andricinline constexpr
2363*b5893f02SDimitry Andricyear_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
2364*b5893f02SDimitry Andric{ return __lhs / __rhs.month() / __rhs.day(); }
2365*b5893f02SDimitry Andric
2366*b5893f02SDimitry Andricinline constexpr
2367*b5893f02SDimitry Andricyear_month_day operator/(int __lhs, const month_day& __rhs) noexcept
2368*b5893f02SDimitry Andric{ return year(__lhs) / __rhs; }
2369*b5893f02SDimitry Andric
2370*b5893f02SDimitry Andricinline constexpr
2371*b5893f02SDimitry Andricyear_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
2372*b5893f02SDimitry Andric{ return __rhs / __lhs; }
2373*b5893f02SDimitry Andric
2374*b5893f02SDimitry Andricinline constexpr
2375*b5893f02SDimitry Andricyear_month_day operator/(const month_day& __lhs, int __rhs) noexcept
2376*b5893f02SDimitry Andric{ return year(__rhs) / __lhs; }
2377*b5893f02SDimitry Andric
2378*b5893f02SDimitry Andric
2379*b5893f02SDimitry Andricinline constexpr
2380*b5893f02SDimitry Andricyear_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
2381*b5893f02SDimitry Andric{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
2382*b5893f02SDimitry Andric
2383*b5893f02SDimitry Andricinline constexpr
2384*b5893f02SDimitry Andricyear_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
2385*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2386*b5893f02SDimitry Andric
2387*b5893f02SDimitry Andricinline constexpr
2388*b5893f02SDimitry Andricyear_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
2389*b5893f02SDimitry Andric{ return __lhs + -__rhs; }
2390*b5893f02SDimitry Andric
2391*b5893f02SDimitry Andricinline constexpr
2392*b5893f02SDimitry Andricyear_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
2393*b5893f02SDimitry Andric{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
2394*b5893f02SDimitry Andric
2395*b5893f02SDimitry Andricinline constexpr
2396*b5893f02SDimitry Andricyear_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
2397*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2398*b5893f02SDimitry Andric
2399*b5893f02SDimitry Andricinline constexpr
2400*b5893f02SDimitry Andricyear_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
2401*b5893f02SDimitry Andric{ return __lhs + -__rhs; }
2402*b5893f02SDimitry Andric
2403*b5893f02SDimitry Andricinline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2404*b5893f02SDimitry Andricinline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2405*b5893f02SDimitry Andricinline constexpr year_month_day& year_month_day::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
2406*b5893f02SDimitry Andricinline constexpr year_month_day& year_month_day::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
2407*b5893f02SDimitry Andric
2408*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS year_month_day_last {
2409*b5893f02SDimitry Andricprivate:
2410*b5893f02SDimitry Andric    chrono::year           __y;
2411*b5893f02SDimitry Andric    chrono::month_day_last __mdl;
2412*b5893f02SDimitry Andricpublic:
2413*b5893f02SDimitry Andric     constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
2414*b5893f02SDimitry Andric        : __y{__yval}, __mdl{__mdlval} {}
2415*b5893f02SDimitry Andric
2416*b5893f02SDimitry Andric     constexpr year_month_day_last& operator+=(const months& __m) noexcept;
2417*b5893f02SDimitry Andric     constexpr year_month_day_last& operator-=(const months& __m) noexcept;
2418*b5893f02SDimitry Andric     constexpr year_month_day_last& operator+=(const years& __y)  noexcept;
2419*b5893f02SDimitry Andric     constexpr year_month_day_last& operator-=(const years& __y)  noexcept;
2420*b5893f02SDimitry Andric
2421*b5893f02SDimitry Andric     inline constexpr chrono::year                     year() const noexcept { return __y; }
2422*b5893f02SDimitry Andric     inline constexpr chrono::month                   month() const noexcept { return __mdl.month(); }
2423*b5893f02SDimitry Andric     inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
2424*b5893f02SDimitry Andric            constexpr chrono::day                       day() const noexcept;
2425*b5893f02SDimitry Andric     inline constexpr operator                     sys_days() const noexcept { return   sys_days{year()/month()/day()}; }
2426*b5893f02SDimitry Andric     inline explicit constexpr operator          local_days() const noexcept { return local_days{year()/month()/day()}; }
2427*b5893f02SDimitry Andric     inline constexpr bool                               ok() const noexcept { return __y.ok() && __mdl.ok(); }
2428*b5893f02SDimitry Andric};
2429*b5893f02SDimitry Andric
2430*b5893f02SDimitry Andricinline constexpr
2431*b5893f02SDimitry Andricchrono::day year_month_day_last::day() const noexcept
2432*b5893f02SDimitry Andric{
2433*b5893f02SDimitry Andric    constexpr chrono::day __d[] =
2434*b5893f02SDimitry Andric    {
2435*b5893f02SDimitry Andric        chrono::day(31), chrono::day(28), chrono::day(31),
2436*b5893f02SDimitry Andric        chrono::day(30), chrono::day(31), chrono::day(30),
2437*b5893f02SDimitry Andric        chrono::day(31), chrono::day(31), chrono::day(30),
2438*b5893f02SDimitry Andric        chrono::day(31), chrono::day(30), chrono::day(31)
2439*b5893f02SDimitry Andric    };
2440*b5893f02SDimitry Andric    return month() != February || !__y.is_leap() ?
2441*b5893f02SDimitry Andric        __d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
2442*b5893f02SDimitry Andric}
2443*b5893f02SDimitry Andric
2444*b5893f02SDimitry Andricinline constexpr
2445*b5893f02SDimitry Andricbool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2446*b5893f02SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
2447*b5893f02SDimitry Andric
2448*b5893f02SDimitry Andricinline constexpr
2449*b5893f02SDimitry Andricbool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2450*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
2451*b5893f02SDimitry Andric
2452*b5893f02SDimitry Andricinline constexpr
2453*b5893f02SDimitry Andricbool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2454*b5893f02SDimitry Andric{
2455*b5893f02SDimitry Andric    if (__lhs.year() < __rhs.year()) return true;
2456*b5893f02SDimitry Andric    if (__lhs.year() > __rhs.year()) return false;
2457*b5893f02SDimitry Andric    return __lhs.month_day_last() < __rhs.month_day_last();
2458*b5893f02SDimitry Andric}
2459*b5893f02SDimitry Andric
2460*b5893f02SDimitry Andricinline constexpr
2461*b5893f02SDimitry Andricbool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2462*b5893f02SDimitry Andric{ return __rhs < __lhs; }
2463*b5893f02SDimitry Andric
2464*b5893f02SDimitry Andricinline constexpr
2465*b5893f02SDimitry Andricbool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2466*b5893f02SDimitry Andric{ return !(__rhs < __lhs);}
2467*b5893f02SDimitry Andric
2468*b5893f02SDimitry Andricinline constexpr
2469*b5893f02SDimitry Andricbool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
2470*b5893f02SDimitry Andric{ return !(__lhs < __rhs); }
2471*b5893f02SDimitry Andric
2472*b5893f02SDimitry Andricinline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
2473*b5893f02SDimitry Andric{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
2474*b5893f02SDimitry Andric
2475*b5893f02SDimitry Andricinline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
2476*b5893f02SDimitry Andric{ return year_month_day_last{__lhs, __rhs}; }
2477*b5893f02SDimitry Andric
2478*b5893f02SDimitry Andricinline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
2479*b5893f02SDimitry Andric{ return year_month_day_last{year{__lhs}, __rhs}; }
2480*b5893f02SDimitry Andric
2481*b5893f02SDimitry Andricinline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept
2482*b5893f02SDimitry Andric{ return __rhs / __lhs; }
2483*b5893f02SDimitry Andric
2484*b5893f02SDimitry Andricinline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
2485*b5893f02SDimitry Andric{ return year{__rhs} / __lhs; }
2486*b5893f02SDimitry Andric
2487*b5893f02SDimitry Andric
2488*b5893f02SDimitry Andricinline constexpr
2489*b5893f02SDimitry Andricyear_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
2490*b5893f02SDimitry Andric{ return (__lhs.year() / __lhs.month() + __rhs) / last; }
2491*b5893f02SDimitry Andric
2492*b5893f02SDimitry Andricinline constexpr
2493*b5893f02SDimitry Andricyear_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
2494*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2495*b5893f02SDimitry Andric
2496*b5893f02SDimitry Andricinline constexpr
2497*b5893f02SDimitry Andricyear_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
2498*b5893f02SDimitry Andric{ return __lhs + (-__rhs); }
2499*b5893f02SDimitry Andric
2500*b5893f02SDimitry Andricinline constexpr
2501*b5893f02SDimitry Andricyear_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
2502*b5893f02SDimitry Andric{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
2503*b5893f02SDimitry Andric
2504*b5893f02SDimitry Andricinline constexpr
2505*b5893f02SDimitry Andricyear_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
2506*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2507*b5893f02SDimitry Andric
2508*b5893f02SDimitry Andricinline constexpr
2509*b5893f02SDimitry Andricyear_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
2510*b5893f02SDimitry Andric{ return __lhs + (-__rhs); }
2511*b5893f02SDimitry Andric
2512*b5893f02SDimitry Andricinline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2513*b5893f02SDimitry Andricinline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2514*b5893f02SDimitry Andricinline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
2515*b5893f02SDimitry Andricinline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
2516*b5893f02SDimitry Andric
2517*b5893f02SDimitry Andricinline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
2518*b5893f02SDimitry Andric    : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}
2519*b5893f02SDimitry Andric
2520*b5893f02SDimitry Andricinline constexpr bool year_month_day::ok() const noexcept
2521*b5893f02SDimitry Andric{
2522*b5893f02SDimitry Andric    if (!__y.ok() || !__m.ok()) return false;
2523*b5893f02SDimitry Andric    return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
2524*b5893f02SDimitry Andric}
2525*b5893f02SDimitry Andric
2526*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS year_month_weekday {
2527*b5893f02SDimitry Andric    chrono::year            __y;
2528*b5893f02SDimitry Andric    chrono::month           __m;
2529*b5893f02SDimitry Andric    chrono::weekday_indexed __wdi;
2530*b5893f02SDimitry Andricpublic:
2531*b5893f02SDimitry Andric    year_month_weekday() = default;
2532*b5893f02SDimitry Andric    constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
2533*b5893f02SDimitry Andric                               const chrono::weekday_indexed& __wdival) noexcept
2534*b5893f02SDimitry Andric        : __y{__yval}, __m{__mval}, __wdi{__wdival} {}
2535*b5893f02SDimitry Andric    constexpr year_month_weekday(const sys_days& __sysd) noexcept
2536*b5893f02SDimitry Andric            : year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
2537*b5893f02SDimitry Andric    inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
2538*b5893f02SDimitry Andric            : year_month_weekday(__from_days(__locd.time_since_epoch())) {}
2539*b5893f02SDimitry Andric    constexpr year_month_weekday& operator+=(const months& m) noexcept;
2540*b5893f02SDimitry Andric    constexpr year_month_weekday& operator-=(const months& m) noexcept;
2541*b5893f02SDimitry Andric    constexpr year_month_weekday& operator+=(const years& y)  noexcept;
2542*b5893f02SDimitry Andric    constexpr year_month_weekday& operator-=(const years& y)  noexcept;
2543*b5893f02SDimitry Andric
2544*b5893f02SDimitry Andric    inline constexpr chrono::year                       year() const noexcept { return __y; }
2545*b5893f02SDimitry Andric    inline constexpr chrono::month                     month() const noexcept { return __m; }
2546*b5893f02SDimitry Andric    inline constexpr chrono::weekday                 weekday() const noexcept { return __wdi.weekday(); }
2547*b5893f02SDimitry Andric    inline constexpr unsigned                          index() const noexcept { return __wdi.index(); }
2548*b5893f02SDimitry Andric    inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
2549*b5893f02SDimitry Andric
2550*b5893f02SDimitry Andric    inline constexpr                       operator sys_days() const noexcept { return   sys_days{__to_days()}; }
2551*b5893f02SDimitry Andric    inline explicit constexpr operator            local_days() const noexcept { return local_days{__to_days()}; }
2552*b5893f02SDimitry Andric    inline constexpr bool ok() const noexcept
2553*b5893f02SDimitry Andric    {
2554*b5893f02SDimitry Andric        if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
2555*b5893f02SDimitry Andric    //  TODO: make sure it's a valid date
2556*b5893f02SDimitry Andric        return true;
2557*b5893f02SDimitry Andric    }
2558*b5893f02SDimitry Andric
2559*b5893f02SDimitry Andric    static constexpr year_month_weekday __from_days(days __d) noexcept;
2560*b5893f02SDimitry Andric    constexpr days __to_days() const noexcept;
2561*b5893f02SDimitry Andric};
2562*b5893f02SDimitry Andric
2563*b5893f02SDimitry Andricinline constexpr
2564*b5893f02SDimitry Andricyear_month_weekday year_month_weekday::__from_days(days __d) noexcept
2565*b5893f02SDimitry Andric{
2566*b5893f02SDimitry Andric    const sys_days      __sysd{__d};
2567*b5893f02SDimitry Andric    const chrono::weekday __wd = chrono::weekday(__sysd);
2568*b5893f02SDimitry Andric    const year_month_day __ymd = year_month_day(__sysd);
2569*b5893f02SDimitry Andric    return year_month_weekday{__ymd.year(), __ymd.month(),
2570*b5893f02SDimitry Andric                              __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
2571*b5893f02SDimitry Andric}
2572*b5893f02SDimitry Andric
2573*b5893f02SDimitry Andricinline constexpr
2574*b5893f02SDimitry Andricdays year_month_weekday::__to_days() const noexcept
2575*b5893f02SDimitry Andric{
2576*b5893f02SDimitry Andric    const sys_days __sysd = sys_days(__y/__m/1);
2577*b5893f02SDimitry Andric    return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
2578*b5893f02SDimitry Andric                .time_since_epoch();
2579*b5893f02SDimitry Andric}
2580*b5893f02SDimitry Andric
2581*b5893f02SDimitry Andricinline constexpr
2582*b5893f02SDimitry Andricbool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
2583*b5893f02SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
2584*b5893f02SDimitry Andric
2585*b5893f02SDimitry Andricinline constexpr
2586*b5893f02SDimitry Andricbool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
2587*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
2588*b5893f02SDimitry Andric
2589*b5893f02SDimitry Andricinline constexpr
2590*b5893f02SDimitry Andricyear_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
2591*b5893f02SDimitry Andric{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
2592*b5893f02SDimitry Andric
2593*b5893f02SDimitry Andricinline constexpr
2594*b5893f02SDimitry Andricyear_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
2595*b5893f02SDimitry Andric{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
2596*b5893f02SDimitry Andric
2597*b5893f02SDimitry Andricinline constexpr
2598*b5893f02SDimitry Andricyear_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
2599*b5893f02SDimitry Andric{ return year(__lhs) / __rhs; }
2600*b5893f02SDimitry Andric
2601*b5893f02SDimitry Andricinline constexpr
2602*b5893f02SDimitry Andricyear_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
2603*b5893f02SDimitry Andric{ return __rhs / __lhs; }
2604*b5893f02SDimitry Andric
2605*b5893f02SDimitry Andricinline constexpr
2606*b5893f02SDimitry Andricyear_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
2607*b5893f02SDimitry Andric{ return year(__rhs) / __lhs; }
2608*b5893f02SDimitry Andric
2609*b5893f02SDimitry Andric
2610*b5893f02SDimitry Andricinline constexpr
2611*b5893f02SDimitry Andricyear_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
2612*b5893f02SDimitry Andric{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
2613*b5893f02SDimitry Andric
2614*b5893f02SDimitry Andricinline constexpr
2615*b5893f02SDimitry Andricyear_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
2616*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2617*b5893f02SDimitry Andric
2618*b5893f02SDimitry Andricinline constexpr
2619*b5893f02SDimitry Andricyear_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
2620*b5893f02SDimitry Andric{ return __lhs + (-__rhs); }
2621*b5893f02SDimitry Andric
2622*b5893f02SDimitry Andricinline constexpr
2623*b5893f02SDimitry Andricyear_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
2624*b5893f02SDimitry Andric{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
2625*b5893f02SDimitry Andric
2626*b5893f02SDimitry Andricinline constexpr
2627*b5893f02SDimitry Andricyear_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
2628*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2629*b5893f02SDimitry Andric
2630*b5893f02SDimitry Andricinline constexpr
2631*b5893f02SDimitry Andricyear_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
2632*b5893f02SDimitry Andric{ return __lhs + (-__rhs); }
2633*b5893f02SDimitry Andric
2634*b5893f02SDimitry Andric
2635*b5893f02SDimitry Andricinline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2636*b5893f02SDimitry Andricinline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2637*b5893f02SDimitry Andricinline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
2638*b5893f02SDimitry Andricinline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
2639*b5893f02SDimitry Andric
2640*b5893f02SDimitry Andricclass _LIBCPP_TYPE_VIS year_month_weekday_last {
2641*b5893f02SDimitry Andricprivate:
2642*b5893f02SDimitry Andric    chrono::year         __y;
2643*b5893f02SDimitry Andric    chrono::month        __m;
2644*b5893f02SDimitry Andric    chrono::weekday_last __wdl;
2645*b5893f02SDimitry Andricpublic:
2646*b5893f02SDimitry Andric    constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
2647*b5893f02SDimitry Andric                                      const chrono::weekday_last& __wdlval) noexcept
2648*b5893f02SDimitry Andric                : __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
2649*b5893f02SDimitry Andric    constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
2650*b5893f02SDimitry Andric    constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
2651*b5893f02SDimitry Andric    constexpr year_month_weekday_last& operator+=(const years& __dy)  noexcept;
2652*b5893f02SDimitry Andric    constexpr year_month_weekday_last& operator-=(const years& __dy)  noexcept;
2653*b5893f02SDimitry Andric
2654*b5893f02SDimitry Andric    inline constexpr chrono::year                 year() const noexcept { return __y; }
2655*b5893f02SDimitry Andric    inline constexpr chrono::month               month() const noexcept { return __m; }
2656*b5893f02SDimitry Andric    inline constexpr chrono::weekday           weekday() const noexcept { return __wdl.weekday(); }
2657*b5893f02SDimitry Andric    inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
2658*b5893f02SDimitry Andric    inline constexpr operator                 sys_days() const noexcept { return   sys_days{__to_days()}; }
2659*b5893f02SDimitry Andric    inline explicit constexpr operator      local_days() const noexcept { return local_days{__to_days()}; }
2660*b5893f02SDimitry Andric    inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
2661*b5893f02SDimitry Andric
2662*b5893f02SDimitry Andric    constexpr days __to_days() const noexcept;
2663*b5893f02SDimitry Andric
2664*b5893f02SDimitry Andric};
2665*b5893f02SDimitry Andric
2666*b5893f02SDimitry Andricinline constexpr
2667*b5893f02SDimitry Andricdays year_month_weekday_last::__to_days() const noexcept
2668*b5893f02SDimitry Andric{
2669*b5893f02SDimitry Andric    const sys_days __last = sys_days{__y/__m/last};
2670*b5893f02SDimitry Andric    return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
2671*b5893f02SDimitry Andric
2672*b5893f02SDimitry Andric}
2673*b5893f02SDimitry Andric
2674*b5893f02SDimitry Andricinline constexpr
2675*b5893f02SDimitry Andricbool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
2676*b5893f02SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
2677*b5893f02SDimitry Andric
2678*b5893f02SDimitry Andricinline constexpr
2679*b5893f02SDimitry Andricbool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
2680*b5893f02SDimitry Andric{ return !(__lhs == __rhs); }
2681*b5893f02SDimitry Andric
2682*b5893f02SDimitry Andric
2683*b5893f02SDimitry Andricinline constexpr
2684*b5893f02SDimitry Andricyear_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
2685*b5893f02SDimitry Andric{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
2686*b5893f02SDimitry Andric
2687*b5893f02SDimitry Andricinline constexpr
2688*b5893f02SDimitry Andricyear_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
2689*b5893f02SDimitry Andric{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
2690*b5893f02SDimitry Andric
2691*b5893f02SDimitry Andricinline constexpr
2692*b5893f02SDimitry Andricyear_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
2693*b5893f02SDimitry Andric{ return year(__lhs) / __rhs; }
2694*b5893f02SDimitry Andric
2695*b5893f02SDimitry Andricinline constexpr
2696*b5893f02SDimitry Andricyear_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
2697*b5893f02SDimitry Andric{ return __rhs / __lhs; }
2698*b5893f02SDimitry Andric
2699*b5893f02SDimitry Andricinline constexpr
2700*b5893f02SDimitry Andricyear_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
2701*b5893f02SDimitry Andric{ return year(__rhs) / __lhs; }
2702*b5893f02SDimitry Andric
2703*b5893f02SDimitry Andric
2704*b5893f02SDimitry Andricinline constexpr
2705*b5893f02SDimitry Andricyear_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
2706*b5893f02SDimitry Andric{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
2707*b5893f02SDimitry Andric
2708*b5893f02SDimitry Andricinline constexpr
2709*b5893f02SDimitry Andricyear_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
2710*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2711*b5893f02SDimitry Andric
2712*b5893f02SDimitry Andricinline constexpr
2713*b5893f02SDimitry Andricyear_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
2714*b5893f02SDimitry Andric{ return __lhs + (-__rhs); }
2715*b5893f02SDimitry Andric
2716*b5893f02SDimitry Andricinline constexpr
2717*b5893f02SDimitry Andricyear_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
2718*b5893f02SDimitry Andric{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
2719*b5893f02SDimitry Andric
2720*b5893f02SDimitry Andricinline constexpr
2721*b5893f02SDimitry Andricyear_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
2722*b5893f02SDimitry Andric{ return __rhs + __lhs; }
2723*b5893f02SDimitry Andric
2724*b5893f02SDimitry Andricinline constexpr
2725*b5893f02SDimitry Andricyear_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
2726*b5893f02SDimitry Andric{ return __lhs + (-__rhs); }
2727*b5893f02SDimitry Andric
2728*b5893f02SDimitry Andricinline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
2729*b5893f02SDimitry Andricinline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
2730*b5893f02SDimitry Andricinline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy)  noexcept { *this = *this + __dy; return *this; }
2731*b5893f02SDimitry Andricinline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy)  noexcept { *this = *this - __dy; return *this; }
2732*b5893f02SDimitry Andric
2733*b5893f02SDimitry Andric#endif // _LIBCPP_STD_VER > 17
27347a984708SDavid Chisnall} // chrono
27357a984708SDavid Chisnall
27364f7ab58eSDimitry Andric#if _LIBCPP_STD_VER > 11
27374f7ab58eSDimitry Andric// Suffixes for duration literals [time.duration.literals]
27384f7ab58eSDimitry Andricinline namespace literals
27394f7ab58eSDimitry Andric{
27404f7ab58eSDimitry Andric  inline namespace chrono_literals
27414f7ab58eSDimitry Andric  {
27424f7ab58eSDimitry Andric
27434f7ab58eSDimitry Andric    constexpr chrono::hours operator""h(unsigned long long __h)
27444f7ab58eSDimitry Andric    {
27454f7ab58eSDimitry Andric        return chrono::hours(static_cast<chrono::hours::rep>(__h));
27464f7ab58eSDimitry Andric    }
27474f7ab58eSDimitry Andric
27484f7ab58eSDimitry Andric    constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
27494f7ab58eSDimitry Andric    {
27504f7ab58eSDimitry Andric        return chrono::duration<long double, ratio<3600,1>>(__h);
27514f7ab58eSDimitry Andric    }
27524f7ab58eSDimitry Andric
27534f7ab58eSDimitry Andric
27544f7ab58eSDimitry Andric    constexpr chrono::minutes operator""min(unsigned long long __m)
27554f7ab58eSDimitry Andric    {
27564f7ab58eSDimitry Andric        return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
27574f7ab58eSDimitry Andric    }
27584f7ab58eSDimitry Andric
27594f7ab58eSDimitry Andric    constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
27604f7ab58eSDimitry Andric    {
27614f7ab58eSDimitry Andric        return chrono::duration<long double, ratio<60,1>> (__m);
27624f7ab58eSDimitry Andric    }
27634f7ab58eSDimitry Andric
27644f7ab58eSDimitry Andric
27654f7ab58eSDimitry Andric    constexpr chrono::seconds operator""s(unsigned long long __s)
27664f7ab58eSDimitry Andric    {
27674f7ab58eSDimitry Andric        return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
27684f7ab58eSDimitry Andric    }
27694f7ab58eSDimitry Andric
27704f7ab58eSDimitry Andric    constexpr chrono::duration<long double> operator""s(long double __s)
27714f7ab58eSDimitry Andric    {
27724f7ab58eSDimitry Andric        return chrono::duration<long double> (__s);
27734f7ab58eSDimitry Andric    }
27744f7ab58eSDimitry Andric
27754f7ab58eSDimitry Andric
27764f7ab58eSDimitry Andric    constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
27774f7ab58eSDimitry Andric    {
27784f7ab58eSDimitry Andric        return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
27794f7ab58eSDimitry Andric    }
27804f7ab58eSDimitry Andric
27814f7ab58eSDimitry Andric    constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
27824f7ab58eSDimitry Andric    {
27834f7ab58eSDimitry Andric        return chrono::duration<long double, milli>(__ms);
27844f7ab58eSDimitry Andric    }
27854f7ab58eSDimitry Andric
27864f7ab58eSDimitry Andric
27874f7ab58eSDimitry Andric    constexpr chrono::microseconds operator""us(unsigned long long __us)
27884f7ab58eSDimitry Andric    {
27894f7ab58eSDimitry Andric        return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
27904f7ab58eSDimitry Andric    }
27914f7ab58eSDimitry Andric
27924f7ab58eSDimitry Andric    constexpr chrono::duration<long double, micro> operator""us(long double __us)
27934f7ab58eSDimitry Andric    {
27944f7ab58eSDimitry Andric        return chrono::duration<long double, micro> (__us);
27954f7ab58eSDimitry Andric    }
27964f7ab58eSDimitry Andric
27974f7ab58eSDimitry Andric
27984f7ab58eSDimitry Andric    constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
27994f7ab58eSDimitry Andric    {
28004f7ab58eSDimitry Andric        return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
28014f7ab58eSDimitry Andric    }
28024f7ab58eSDimitry Andric
28034f7ab58eSDimitry Andric    constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
28044f7ab58eSDimitry Andric    {
28054f7ab58eSDimitry Andric        return chrono::duration<long double, nano> (__ns);
28064f7ab58eSDimitry Andric    }
28074f7ab58eSDimitry Andric
2808*b5893f02SDimitry Andric#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS)
2809*b5893f02SDimitry Andric    constexpr chrono::day operator ""d(unsigned long long __d) noexcept
2810*b5893f02SDimitry Andric    {
2811*b5893f02SDimitry Andric        return chrono::day(static_cast<unsigned>(__d));
2812*b5893f02SDimitry Andric    }
2813*b5893f02SDimitry Andric
2814*b5893f02SDimitry Andric    constexpr chrono::year operator ""y(unsigned long long __y) noexcept
2815*b5893f02SDimitry Andric    {
2816*b5893f02SDimitry Andric        return chrono::year(static_cast<int>(__y));
2817*b5893f02SDimitry Andric    }
2818*b5893f02SDimitry Andric#endif
28194f7ab58eSDimitry Andric}}
28204f7ab58eSDimitry Andric
28214f7ab58eSDimitry Andricnamespace chrono { // hoist the literals into namespace std::chrono
28224f7ab58eSDimitry Andric   using namespace literals::chrono_literals;
28234f7ab58eSDimitry Andric}
28244f7ab58eSDimitry Andric
28254f7ab58eSDimitry Andric#endif
28264f7ab58eSDimitry Andric
28277a984708SDavid Chisnall_LIBCPP_END_NAMESPACE_STD
28287a984708SDavid Chisnall
2829*b5893f02SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2830*b5893f02SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
2831*b5893f02SDimitry Andricstruct _FilesystemClock {
2832*b5893f02SDimitry Andric#if !defined(_LIBCPP_HAS_NO_INT128)
2833*b5893f02SDimitry Andric  typedef __int128_t rep;
2834*b5893f02SDimitry Andric  typedef nano period;
2835*b5893f02SDimitry Andric#else
2836*b5893f02SDimitry Andric  typedef long long rep;
2837*b5893f02SDimitry Andric  typedef nano period;
2838*b5893f02SDimitry Andric#endif
2839*b5893f02SDimitry Andric
2840*b5893f02SDimitry Andric  typedef chrono::duration<rep, period> duration;
2841*b5893f02SDimitry Andric  typedef chrono::time_point<_FilesystemClock> time_point;
2842*b5893f02SDimitry Andric
2843*b5893f02SDimitry Andric  static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
2844*b5893f02SDimitry Andric
2845*b5893f02SDimitry Andric  _LIBCPP_FUNC_VIS static time_point now() noexcept;
2846*b5893f02SDimitry Andric
2847*b5893f02SDimitry Andric  _LIBCPP_INLINE_VISIBILITY
2848*b5893f02SDimitry Andric  static time_t to_time_t(const time_point& __t) noexcept {
2849*b5893f02SDimitry Andric      typedef chrono::duration<rep> __secs;
2850*b5893f02SDimitry Andric      return time_t(
2851*b5893f02SDimitry Andric          chrono::duration_cast<__secs>(__t.time_since_epoch()).count());
2852*b5893f02SDimitry Andric  }
2853*b5893f02SDimitry Andric
2854*b5893f02SDimitry Andric  _LIBCPP_INLINE_VISIBILITY
2855*b5893f02SDimitry Andric  static time_point from_time_t(time_t __t) noexcept {
2856*b5893f02SDimitry Andric      typedef chrono::duration<rep> __secs;
2857*b5893f02SDimitry Andric      return time_point(__secs(__t));
2858*b5893f02SDimitry Andric  }
2859*b5893f02SDimitry Andric};
2860*b5893f02SDimitry Andric_LIBCPP_END_NAMESPACE_FILESYSTEM
2861*b5893f02SDimitry Andric#endif // !_LIBCPP_CXX03_LANG
2862*b5893f02SDimitry Andric
2863f9448bf3SDimitry Andric_LIBCPP_POP_MACROS
2864f9448bf3SDimitry Andric
28657a984708SDavid Chisnall#endif  // _LIBCPP_CHRONO
2866