10b57cec5SDimitry Andric// -*- C++ -*- 20b57cec5SDimitry Andric//===---------------------------- chrono ----------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_CHRONO 110b57cec5SDimitry Andric#define _LIBCPP_CHRONO 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric chrono synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andricnamespace chrono 190b57cec5SDimitry Andric{ 200b57cec5SDimitry Andric 210b57cec5SDimitry Andrictemplate <class ToDuration, class Rep, class Period> 220b57cec5SDimitry Andricconstexpr 230b57cec5SDimitry AndricToDuration 240b57cec5SDimitry Andricduration_cast(const duration<Rep, Period>& fd); 250b57cec5SDimitry Andric 260b57cec5SDimitry Andrictemplate <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; 270b57cec5SDimitry Andric 280b57cec5SDimitry Andrictemplate <class Rep> inline constexpr bool treat_as_floating_point_v 290b57cec5SDimitry Andric = treat_as_floating_point<Rep>::value; // C++17 300b57cec5SDimitry Andric 310b57cec5SDimitry Andrictemplate <class Rep> 320b57cec5SDimitry Andricstruct duration_values 330b57cec5SDimitry Andric{ 340b57cec5SDimitry Andricpublic: 350b57cec5SDimitry Andric static constexpr Rep zero(); // noexcept in C++20 360b57cec5SDimitry Andric static constexpr Rep max(); // noexcept in C++20 370b57cec5SDimitry Andric static constexpr Rep min(); // noexcept in C++20 380b57cec5SDimitry Andric}; 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric// duration 410b57cec5SDimitry Andric 420b57cec5SDimitry Andrictemplate <class Rep, class Period = ratio<1>> 430b57cec5SDimitry Andricclass duration 440b57cec5SDimitry Andric{ 450b57cec5SDimitry Andric static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration"); 460b57cec5SDimitry Andric static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio"); 470b57cec5SDimitry Andric static_assert(Period::num > 0, "duration period must be positive"); 480b57cec5SDimitry Andricpublic: 490b57cec5SDimitry Andric typedef Rep rep; 500b57cec5SDimitry Andric typedef typename _Period::type period; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric constexpr duration() = default; 530b57cec5SDimitry Andric template <class Rep2> 540b57cec5SDimitry Andric constexpr explicit duration(const Rep2& r, 550b57cec5SDimitry Andric typename enable_if 560b57cec5SDimitry Andric < 570b57cec5SDimitry Andric is_convertible<Rep2, rep>::value && 580b57cec5SDimitry Andric (treat_as_floating_point<rep>::value || 590b57cec5SDimitry Andric !treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value) 600b57cec5SDimitry Andric >::type* = 0); 610b57cec5SDimitry Andric 620b57cec5SDimitry Andric // conversions 630b57cec5SDimitry Andric template <class Rep2, class Period2> 640b57cec5SDimitry Andric constexpr duration(const duration<Rep2, Period2>& d, 650b57cec5SDimitry Andric typename enable_if 660b57cec5SDimitry Andric < 670b57cec5SDimitry Andric treat_as_floating_point<rep>::value || 680b57cec5SDimitry Andric ratio_divide<Period2, period>::type::den == 1 690b57cec5SDimitry Andric >::type* = 0); 700b57cec5SDimitry Andric 710b57cec5SDimitry Andric // observer 720b57cec5SDimitry Andric 730b57cec5SDimitry Andric constexpr rep count() const; 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric // arithmetic 760b57cec5SDimitry Andric 770b57cec5SDimitry Andric constexpr common_type<duration>::type operator+() const; 780b57cec5SDimitry Andric constexpr common_type<duration>::type operator-() const; 790b57cec5SDimitry Andric constexpr duration& operator++(); // constexpr in C++17 800b57cec5SDimitry Andric constexpr duration operator++(int); // constexpr in C++17 810b57cec5SDimitry Andric constexpr duration& operator--(); // constexpr in C++17 820b57cec5SDimitry Andric constexpr duration operator--(int); // constexpr in C++17 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric constexpr duration& operator+=(const duration& d); // constexpr in C++17 850b57cec5SDimitry Andric constexpr duration& operator-=(const duration& d); // constexpr in C++17 860b57cec5SDimitry Andric 870b57cec5SDimitry Andric duration& operator*=(const rep& rhs); // constexpr in C++17 880b57cec5SDimitry Andric duration& operator/=(const rep& rhs); // constexpr in C++17 890b57cec5SDimitry Andric duration& operator%=(const rep& rhs); // constexpr in C++17 900b57cec5SDimitry Andric duration& operator%=(const duration& rhs); // constexpr in C++17 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric // special values 930b57cec5SDimitry Andric 940b57cec5SDimitry Andric static constexpr duration zero(); // noexcept in C++20 950b57cec5SDimitry Andric static constexpr duration min(); // noexcept in C++20 960b57cec5SDimitry Andric static constexpr duration max(); // noexcept in C++20 970b57cec5SDimitry Andric}; 980b57cec5SDimitry Andric 990b57cec5SDimitry Andrictypedef duration<long long, nano> nanoseconds; 1000b57cec5SDimitry Andrictypedef duration<long long, micro> microseconds; 1010b57cec5SDimitry Andrictypedef duration<long long, milli> milliseconds; 1020b57cec5SDimitry Andrictypedef duration<long long > seconds; 1030b57cec5SDimitry Andrictypedef duration< long, ratio< 60> > minutes; 1040b57cec5SDimitry Andrictypedef duration< long, ratio<3600> > hours; 1050b57cec5SDimitry Andric 1060b57cec5SDimitry Andrictemplate <class Clock, class Duration = typename Clock::duration> 1070b57cec5SDimitry Andricclass time_point 1080b57cec5SDimitry Andric{ 1090b57cec5SDimitry Andricpublic: 1100b57cec5SDimitry Andric typedef Clock clock; 1110b57cec5SDimitry Andric typedef Duration duration; 1120b57cec5SDimitry Andric typedef typename duration::rep rep; 1130b57cec5SDimitry Andric typedef typename duration::period period; 1140b57cec5SDimitry Andricprivate: 1150b57cec5SDimitry Andric duration d_; // exposition only 1160b57cec5SDimitry Andric 1170b57cec5SDimitry Andricpublic: 1180b57cec5SDimitry Andric time_point(); // has value "epoch" // constexpr in C++14 1190b57cec5SDimitry Andric explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric // conversions 1220b57cec5SDimitry Andric template <class Duration2> 1230b57cec5SDimitry Andric time_point(const time_point<clock, Duration2>& t); // constexpr in C++14 1240b57cec5SDimitry Andric 1250b57cec5SDimitry Andric // observer 1260b57cec5SDimitry Andric 1270b57cec5SDimitry Andric duration time_since_epoch() const; // constexpr in C++14 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andric // arithmetic 1300b57cec5SDimitry Andric 1310b57cec5SDimitry Andric time_point& operator+=(const duration& d); // constexpr in C++17 1320b57cec5SDimitry Andric time_point& operator-=(const duration& d); // constexpr in C++17 1330b57cec5SDimitry Andric 1340b57cec5SDimitry Andric // special values 1350b57cec5SDimitry Andric 1360b57cec5SDimitry Andric static constexpr time_point min(); // noexcept in C++20 1370b57cec5SDimitry Andric static constexpr time_point max(); // noexcept in C++20 1380b57cec5SDimitry Andric}; 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andric} // chrono 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andric// common_type traits 1430b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1440b57cec5SDimitry Andric struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>; 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Duration2> 1470b57cec5SDimitry Andric struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>; 1480b57cec5SDimitry Andric 1490b57cec5SDimitry Andricnamespace chrono { 1500b57cec5SDimitry Andric 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andrictemplate<class T> struct is_clock; // C++20 1530b57cec5SDimitry Andrictemplate<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andric 1560b57cec5SDimitry Andric// duration arithmetic 1570b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1580b57cec5SDimitry Andric constexpr 1590b57cec5SDimitry Andric typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 1600b57cec5SDimitry Andric operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 1610b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1620b57cec5SDimitry Andric constexpr 1630b57cec5SDimitry Andric typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 1640b57cec5SDimitry Andric operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 1650b57cec5SDimitry Andrictemplate <class Rep1, class Period, class Rep2> 1660b57cec5SDimitry Andric constexpr 1670b57cec5SDimitry Andric duration<typename common_type<Rep1, Rep2>::type, Period> 1680b57cec5SDimitry Andric operator*(const duration<Rep1, Period>& d, const Rep2& s); 1690b57cec5SDimitry Andrictemplate <class Rep1, class Period, class Rep2> 1700b57cec5SDimitry Andric constexpr 1710b57cec5SDimitry Andric duration<typename common_type<Rep1, Rep2>::type, Period> 1720b57cec5SDimitry Andric operator*(const Rep1& s, const duration<Rep2, Period>& d); 1730b57cec5SDimitry Andrictemplate <class Rep1, class Period, class Rep2> 1740b57cec5SDimitry Andric constexpr 1750b57cec5SDimitry Andric duration<typename common_type<Rep1, Rep2>::type, Period> 1760b57cec5SDimitry Andric operator/(const duration<Rep1, Period>& d, const Rep2& s); 1770b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1780b57cec5SDimitry Andric constexpr 1790b57cec5SDimitry Andric typename common_type<Rep1, Rep2>::type 1800b57cec5SDimitry Andric operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 1810b57cec5SDimitry Andric 1820b57cec5SDimitry Andric// duration comparisons 1830b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1840b57cec5SDimitry Andric constexpr 1850b57cec5SDimitry Andric bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 1860b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1870b57cec5SDimitry Andric constexpr 1880b57cec5SDimitry Andric bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 1890b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1900b57cec5SDimitry Andric constexpr 1910b57cec5SDimitry Andric bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 1920b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1930b57cec5SDimitry Andric constexpr 1940b57cec5SDimitry Andric bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 1950b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1960b57cec5SDimitry Andric constexpr 1970b57cec5SDimitry Andric bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 1980b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Rep2, class Period2> 1990b57cec5SDimitry Andric constexpr 2000b57cec5SDimitry Andric bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 2010b57cec5SDimitry Andric 2020b57cec5SDimitry Andric// duration_cast 2030b57cec5SDimitry Andrictemplate <class ToDuration, class Rep, class Period> 2040b57cec5SDimitry Andric ToDuration duration_cast(const duration<Rep, Period>& d); 2050b57cec5SDimitry Andric 2060b57cec5SDimitry Andrictemplate <class ToDuration, class Rep, class Period> 2070b57cec5SDimitry Andric constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17 2080b57cec5SDimitry Andrictemplate <class ToDuration, class Rep, class Period> 2090b57cec5SDimitry Andric constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17 2100b57cec5SDimitry Andrictemplate <class ToDuration, class Rep, class Period> 2110b57cec5SDimitry Andric constexpr ToDuration round(const duration<Rep, Period>& d); // C++17 2120b57cec5SDimitry Andric 2130b57cec5SDimitry Andric// duration I/O is elsewhere 2140b57cec5SDimitry Andric 2150b57cec5SDimitry Andric// time_point arithmetic (all constexpr in C++14) 2160b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Rep2, class Period2> 2170b57cec5SDimitry Andric time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 2180b57cec5SDimitry Andric operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 2190b57cec5SDimitry Andrictemplate <class Rep1, class Period1, class Clock, class Duration2> 2200b57cec5SDimitry Andric time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type> 2210b57cec5SDimitry Andric operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs); 2220b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Rep2, class Period2> 2230b57cec5SDimitry Andric time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 2240b57cec5SDimitry Andric operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 2250b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Duration2> 2260b57cec5SDimitry Andric typename common_type<Duration1, Duration2>::type 2270b57cec5SDimitry Andric operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 2280b57cec5SDimitry Andric 2290b57cec5SDimitry Andric// time_point comparisons (all constexpr in C++14) 2300b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Duration2> 2310b57cec5SDimitry Andric bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 2320b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Duration2> 2330b57cec5SDimitry Andric bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 2340b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Duration2> 2350b57cec5SDimitry Andric bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 2360b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Duration2> 2370b57cec5SDimitry Andric bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 2380b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Duration2> 2390b57cec5SDimitry Andric bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 2400b57cec5SDimitry Andrictemplate <class Clock, class Duration1, class Duration2> 2410b57cec5SDimitry Andric bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs); 2420b57cec5SDimitry Andric 2430b57cec5SDimitry Andric// time_point_cast (constexpr in C++14) 2440b57cec5SDimitry Andric 2450b57cec5SDimitry Andrictemplate <class ToDuration, class Clock, class Duration> 2460b57cec5SDimitry Andric time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); 2470b57cec5SDimitry Andric 2480b57cec5SDimitry Andrictemplate <class ToDuration, class Clock, class Duration> 2490b57cec5SDimitry Andric constexpr time_point<Clock, ToDuration> 2500b57cec5SDimitry Andric floor(const time_point<Clock, Duration>& tp); // C++17 2510b57cec5SDimitry Andric 2520b57cec5SDimitry Andrictemplate <class ToDuration, class Clock, class Duration> 2530b57cec5SDimitry Andric constexpr time_point<Clock, ToDuration> 2540b57cec5SDimitry Andric ceil(const time_point<Clock, Duration>& tp); // C++17 2550b57cec5SDimitry Andric 2560b57cec5SDimitry Andrictemplate <class ToDuration, class Clock, class Duration> 2570b57cec5SDimitry Andric constexpr time_point<Clock, ToDuration> 2580b57cec5SDimitry Andric round(const time_point<Clock, Duration>& tp); // C++17 2590b57cec5SDimitry Andric 2600b57cec5SDimitry Andrictemplate <class Rep, class Period> 2610b57cec5SDimitry Andric constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17 2620b57cec5SDimitry Andric 2630b57cec5SDimitry Andric// Clocks 2640b57cec5SDimitry Andric 2650b57cec5SDimitry Andricclass system_clock 2660b57cec5SDimitry Andric{ 2670b57cec5SDimitry Andricpublic: 2680b57cec5SDimitry Andric typedef microseconds duration; 2690b57cec5SDimitry Andric typedef duration::rep rep; 2700b57cec5SDimitry Andric typedef duration::period period; 2710b57cec5SDimitry Andric typedef chrono::time_point<system_clock> time_point; 2720b57cec5SDimitry Andric static const bool is_steady = false; // constexpr in C++14 2730b57cec5SDimitry Andric 2740b57cec5SDimitry Andric static time_point now() noexcept; 2750b57cec5SDimitry Andric static time_t to_time_t (const time_point& __t) noexcept; 2760b57cec5SDimitry Andric static time_point from_time_t(time_t __t) noexcept; 2770b57cec5SDimitry Andric}; 2780b57cec5SDimitry Andric 2790b57cec5SDimitry Andrictemplate <class Duration> 2800b57cec5SDimitry Andric using sys_time = time_point<system_clock, Duration>; // C++20 2810b57cec5SDimitry Andricusing sys_seconds = sys_time<seconds>; // C++20 2820b57cec5SDimitry Andricusing sys_days = sys_time<days>; // C++20 2830b57cec5SDimitry Andric 2840b57cec5SDimitry Andricclass utc_clock; // C++20 2850b57cec5SDimitry Andric 2860b57cec5SDimitry Andrictemplate <class Duration> 2870b57cec5SDimitry Andric using utc_time = time_point<utc_clock, Duration>; // C++20 2880b57cec5SDimitry Andricusing utc_seconds = utc_time<seconds>; // C++20 2890b57cec5SDimitry Andric 2900b57cec5SDimitry Andricclass tai_clock; // C++20 2910b57cec5SDimitry Andric 2920b57cec5SDimitry Andrictemplate <class Duration> 2930b57cec5SDimitry Andric using tai_time = time_point<tai_clock, Duration>; // C++20 2940b57cec5SDimitry Andricusing tai_seconds = tai_time<seconds>; // C++20 2950b57cec5SDimitry Andric 2960b57cec5SDimitry Andricclass file_clock; // C++20 2970b57cec5SDimitry Andric 2980b57cec5SDimitry Andrictemplate<class Duration> 2990b57cec5SDimitry Andric using file_time = time_point<file_clock, Duration>; // C++20 3000b57cec5SDimitry Andric 3010b57cec5SDimitry Andricclass steady_clock 3020b57cec5SDimitry Andric{ 3030b57cec5SDimitry Andricpublic: 3040b57cec5SDimitry Andric typedef nanoseconds duration; 3050b57cec5SDimitry Andric typedef duration::rep rep; 3060b57cec5SDimitry Andric typedef duration::period period; 3070b57cec5SDimitry Andric typedef chrono::time_point<steady_clock, duration> time_point; 3080b57cec5SDimitry Andric static const bool is_steady = true; // constexpr in C++14 3090b57cec5SDimitry Andric 3100b57cec5SDimitry Andric static time_point now() noexcept; 3110b57cec5SDimitry Andric}; 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andrictypedef steady_clock high_resolution_clock; 3140b57cec5SDimitry Andric 3150b57cec5SDimitry Andric// 25.7.8, local time // C++20 3160b57cec5SDimitry Andricstruct local_t {}; 3170b57cec5SDimitry Andrictemplate<class Duration> 3180b57cec5SDimitry Andric using local_time = time_point<local_t, Duration>; 3190b57cec5SDimitry Andricusing local_seconds = local_time<seconds>; 3200b57cec5SDimitry Andricusing local_days = local_time<days>; 3210b57cec5SDimitry Andric 3220b57cec5SDimitry Andric// 25.7.9, time_point conversions template<class DestClock, class SourceClock> // C++20 3230b57cec5SDimitry Andricstruct clock_time_conversion; 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andrictemplate<class DestClock, class SourceClock, class Duration> 3260b57cec5SDimitry Andric auto clock_cast(const time_point<SourceClock, Duration>& t); 3270b57cec5SDimitry Andric 3280b57cec5SDimitry Andric// 25.8.2, class last_spec // C++20 3290b57cec5SDimitry Andricstruct last_spec; 3300b57cec5SDimitry Andric 3310b57cec5SDimitry Andric// 25.8.3, class day // C++20 3320b57cec5SDimitry Andric 3330b57cec5SDimitry Andricclass day; 3340b57cec5SDimitry Andricconstexpr bool operator==(const day& x, const day& y) noexcept; 3350b57cec5SDimitry Andricconstexpr bool operator!=(const day& x, const day& y) noexcept; 3360b57cec5SDimitry Andricconstexpr bool operator< (const day& x, const day& y) noexcept; 3370b57cec5SDimitry Andricconstexpr bool operator> (const day& x, const day& y) noexcept; 3380b57cec5SDimitry Andricconstexpr bool operator<=(const day& x, const day& y) noexcept; 3390b57cec5SDimitry Andricconstexpr bool operator>=(const day& x, const day& y) noexcept; 3400b57cec5SDimitry Andricconstexpr day operator+(const day& x, const days& y) noexcept; 3410b57cec5SDimitry Andricconstexpr day operator+(const days& x, const day& y) noexcept; 3420b57cec5SDimitry Andricconstexpr day operator-(const day& x, const days& y) noexcept; 3430b57cec5SDimitry Andricconstexpr days operator-(const day& x, const day& y) noexcept; 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andric// 25.8.4, class month // C++20 3460b57cec5SDimitry Andricclass month; 3470b57cec5SDimitry Andricconstexpr bool operator==(const month& x, const month& y) noexcept; 3480b57cec5SDimitry Andricconstexpr bool operator!=(const month& x, const month& y) noexcept; 3490b57cec5SDimitry Andricconstexpr bool operator< (const month& x, const month& y) noexcept; 3500b57cec5SDimitry Andricconstexpr bool operator> (const month& x, const month& y) noexcept; 3510b57cec5SDimitry Andricconstexpr bool operator<=(const month& x, const month& y) noexcept; 3520b57cec5SDimitry Andricconstexpr bool operator>=(const month& x, const month& y) noexcept; 3530b57cec5SDimitry Andricconstexpr month operator+(const month& x, const months& y) noexcept; 3540b57cec5SDimitry Andricconstexpr month operator+(const months& x, const month& y) noexcept; 3550b57cec5SDimitry Andricconstexpr month operator-(const month& x, const months& y) noexcept; 3560b57cec5SDimitry Andricconstexpr months operator-(const month& x, const month& y) noexcept; 3570b57cec5SDimitry Andric 3580b57cec5SDimitry Andric// 25.8.5, class year // C++20 3590b57cec5SDimitry Andricclass year; 3600b57cec5SDimitry Andricconstexpr bool operator==(const year& x, const year& y) noexcept; 3610b57cec5SDimitry Andricconstexpr bool operator!=(const year& x, const year& y) noexcept; 3620b57cec5SDimitry Andricconstexpr bool operator< (const year& x, const year& y) noexcept; 3630b57cec5SDimitry Andricconstexpr bool operator> (const year& x, const year& y) noexcept; 3640b57cec5SDimitry Andricconstexpr bool operator<=(const year& x, const year& y) noexcept; 3650b57cec5SDimitry Andricconstexpr bool operator>=(const year& x, const year& y) noexcept; 3660b57cec5SDimitry Andricconstexpr year operator+(const year& x, const years& y) noexcept; 3670b57cec5SDimitry Andricconstexpr year operator+(const years& x, const year& y) noexcept; 3680b57cec5SDimitry Andricconstexpr year operator-(const year& x, const years& y) noexcept; 3690b57cec5SDimitry Andricconstexpr years operator-(const year& x, const year& y) noexcept; 3700b57cec5SDimitry Andric 3710b57cec5SDimitry Andric// 25.8.6, class weekday // C++20 3720b57cec5SDimitry Andricclass weekday; 3730b57cec5SDimitry Andric 3740b57cec5SDimitry Andricconstexpr bool operator==(const weekday& x, const weekday& y) noexcept; 3750b57cec5SDimitry Andricconstexpr bool operator!=(const weekday& x, const weekday& y) noexcept; 3760b57cec5SDimitry Andricconstexpr weekday operator+(const weekday& x, const days& y) noexcept; 3770b57cec5SDimitry Andricconstexpr weekday operator+(const days& x, const weekday& y) noexcept; 3780b57cec5SDimitry Andricconstexpr weekday operator-(const weekday& x, const days& y) noexcept; 3790b57cec5SDimitry Andricconstexpr days operator-(const weekday& x, const weekday& y) noexcept; 3800b57cec5SDimitry Andric 3810b57cec5SDimitry Andric// 25.8.7, class weekday_indexed // C++20 3820b57cec5SDimitry Andric 3830b57cec5SDimitry Andricclass weekday_indexed; 3840b57cec5SDimitry Andricconstexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; 3850b57cec5SDimitry Andricconstexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept; 3860b57cec5SDimitry Andric 3870b57cec5SDimitry Andric// 25.8.8, class weekday_last // C++20 3880b57cec5SDimitry Andricclass weekday_last; 3890b57cec5SDimitry Andric 3900b57cec5SDimitry Andricconstexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept; 3910b57cec5SDimitry Andricconstexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept; 3920b57cec5SDimitry Andric 3930b57cec5SDimitry Andric// 25.8.9, class month_day // C++20 3940b57cec5SDimitry Andricclass month_day; 3950b57cec5SDimitry Andric 3960b57cec5SDimitry Andricconstexpr bool operator==(const month_day& x, const month_day& y) noexcept; 3970b57cec5SDimitry Andricconstexpr bool operator!=(const month_day& x, const month_day& y) noexcept; 3980b57cec5SDimitry Andricconstexpr bool operator< (const month_day& x, const month_day& y) noexcept; 3990b57cec5SDimitry Andricconstexpr bool operator> (const month_day& x, const month_day& y) noexcept; 4000b57cec5SDimitry Andricconstexpr bool operator<=(const month_day& x, const month_day& y) noexcept; 4010b57cec5SDimitry Andricconstexpr bool operator>=(const month_day& x, const month_day& y) noexcept; 4020b57cec5SDimitry Andric 4030b57cec5SDimitry Andric 4040b57cec5SDimitry Andric// 25.8.10, class month_day_last // C++20 4050b57cec5SDimitry Andricclass month_day_last; 4060b57cec5SDimitry Andric 4070b57cec5SDimitry Andricconstexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept; 4080b57cec5SDimitry Andricconstexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept; 4090b57cec5SDimitry Andricconstexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept; 4100b57cec5SDimitry Andricconstexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept; 4110b57cec5SDimitry Andricconstexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept; 4120b57cec5SDimitry Andricconstexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept; 4130b57cec5SDimitry Andric 4140b57cec5SDimitry Andric// 25.8.11, class month_weekday // C++20 4150b57cec5SDimitry Andricclass month_weekday; 4160b57cec5SDimitry Andric 4170b57cec5SDimitry Andricconstexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; 4180b57cec5SDimitry Andricconstexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept; 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andric// 25.8.12, class month_weekday_last // C++20 4210b57cec5SDimitry Andricclass month_weekday_last; 4220b57cec5SDimitry Andric 4230b57cec5SDimitry Andricconstexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; 4240b57cec5SDimitry Andricconstexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept; 4250b57cec5SDimitry Andric 4260b57cec5SDimitry Andric 4270b57cec5SDimitry Andric// 25.8.13, class year_month // C++20 4280b57cec5SDimitry Andricclass year_month; 4290b57cec5SDimitry Andric 4300b57cec5SDimitry Andricconstexpr bool operator==(const year_month& x, const year_month& y) noexcept; 4310b57cec5SDimitry Andricconstexpr bool operator!=(const year_month& x, const year_month& y) noexcept; 4320b57cec5SDimitry Andricconstexpr bool operator< (const year_month& x, const year_month& y) noexcept; 4330b57cec5SDimitry Andricconstexpr bool operator> (const year_month& x, const year_month& y) noexcept; 4340b57cec5SDimitry Andricconstexpr bool operator<=(const year_month& x, const year_month& y) noexcept; 4350b57cec5SDimitry Andricconstexpr bool operator>=(const year_month& x, const year_month& y) noexcept; 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andricconstexpr year_month operator+(const year_month& ym, const months& dm) noexcept; 4380b57cec5SDimitry Andricconstexpr year_month operator+(const months& dm, const year_month& ym) noexcept; 4390b57cec5SDimitry Andricconstexpr year_month operator-(const year_month& ym, const months& dm) noexcept; 4400b57cec5SDimitry Andricconstexpr months operator-(const year_month& x, const year_month& y) noexcept; 4410b57cec5SDimitry Andricconstexpr year_month operator+(const year_month& ym, const years& dy) noexcept; 4420b57cec5SDimitry Andricconstexpr year_month operator+(const years& dy, const year_month& ym) noexcept; 4430b57cec5SDimitry Andricconstexpr year_month operator-(const year_month& ym, const years& dy) noexcept; 4440b57cec5SDimitry Andric 4450b57cec5SDimitry Andric// 25.8.14, class year_month_day class // C++20 4460b57cec5SDimitry Andricyear_month_day; 4470b57cec5SDimitry Andric 4480b57cec5SDimitry Andricconstexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept; 4490b57cec5SDimitry Andricconstexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept; 4500b57cec5SDimitry Andricconstexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept; 4510b57cec5SDimitry Andricconstexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept; 4520b57cec5SDimitry Andricconstexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept; 4530b57cec5SDimitry Andricconstexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept; 4540b57cec5SDimitry Andric 4550b57cec5SDimitry Andricconstexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; 4560b57cec5SDimitry Andricconstexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; 4570b57cec5SDimitry Andricconstexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; 4580b57cec5SDimitry Andricconstexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; 4590b57cec5SDimitry Andricconstexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; 4600b57cec5SDimitry Andricconstexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; 4610b57cec5SDimitry Andric 4620b57cec5SDimitry Andric 4630b57cec5SDimitry Andric// 25.8.15, class year_month_day_last // C++20 4640b57cec5SDimitry Andricclass year_month_day_last; 4650b57cec5SDimitry Andric 4660b57cec5SDimitry Andricconstexpr bool operator==(const year_month_day_last& x, 4670b57cec5SDimitry Andric const year_month_day_last& y) noexcept; 4680b57cec5SDimitry Andricconstexpr bool operator!=(const year_month_day_last& x, 4690b57cec5SDimitry Andric const year_month_day_last& y) noexcept; 4700b57cec5SDimitry Andricconstexpr bool operator< (const year_month_day_last& x, 4710b57cec5SDimitry Andric const year_month_day_last& y) noexcept; 4720b57cec5SDimitry Andricconstexpr bool operator> (const year_month_day_last& x, 4730b57cec5SDimitry Andric const year_month_day_last& y) noexcept; 4740b57cec5SDimitry Andricconstexpr bool operator<=(const year_month_day_last& x, 4750b57cec5SDimitry Andric const year_month_day_last& y) noexcept; 4760b57cec5SDimitry Andricconstexpr bool operator>=(const year_month_day_last& x, 4770b57cec5SDimitry Andric const year_month_day_last& y) noexcept; 4780b57cec5SDimitry Andric 4790b57cec5SDimitry Andricconstexpr year_month_day_last 4800b57cec5SDimitry Andric operator+(const year_month_day_last& ymdl, const months& dm) noexcept; 4810b57cec5SDimitry Andricconstexpr year_month_day_last 4820b57cec5SDimitry Andric operator+(const months& dm, const year_month_day_last& ymdl) noexcept; 4830b57cec5SDimitry Andricconstexpr year_month_day_last 4840b57cec5SDimitry Andric operator+(const year_month_day_last& ymdl, const years& dy) noexcept; 4850b57cec5SDimitry Andricconstexpr year_month_day_last 4860b57cec5SDimitry Andric operator+(const years& dy, const year_month_day_last& ymdl) noexcept; 4870b57cec5SDimitry Andricconstexpr year_month_day_last 4880b57cec5SDimitry Andric operator-(const year_month_day_last& ymdl, const months& dm) noexcept; 4890b57cec5SDimitry Andricconstexpr year_month_day_last 4900b57cec5SDimitry Andric operator-(const year_month_day_last& ymdl, const years& dy) noexcept; 4910b57cec5SDimitry Andric 4920b57cec5SDimitry Andric// 25.8.16, class year_month_weekday // C++20 4930b57cec5SDimitry Andricclass year_month_weekday; 4940b57cec5SDimitry Andric 4950b57cec5SDimitry Andricconstexpr bool operator==(const year_month_weekday& x, 4960b57cec5SDimitry Andric const year_month_weekday& y) noexcept; 4970b57cec5SDimitry Andricconstexpr bool operator!=(const year_month_weekday& x, 4980b57cec5SDimitry Andric const year_month_weekday& y) noexcept; 4990b57cec5SDimitry Andric 5000b57cec5SDimitry Andricconstexpr year_month_weekday 5010b57cec5SDimitry Andric operator+(const year_month_weekday& ymwd, const months& dm) noexcept; 5020b57cec5SDimitry Andricconstexpr year_month_weekday 5030b57cec5SDimitry Andric operator+(const months& dm, const year_month_weekday& ymwd) noexcept; 5040b57cec5SDimitry Andricconstexpr year_month_weekday 5050b57cec5SDimitry Andric operator+(const year_month_weekday& ymwd, const years& dy) noexcept; 5060b57cec5SDimitry Andricconstexpr year_month_weekday 5070b57cec5SDimitry Andric operator+(const years& dy, const year_month_weekday& ymwd) noexcept; 5080b57cec5SDimitry Andricconstexpr year_month_weekday 5090b57cec5SDimitry Andric operator-(const year_month_weekday& ymwd, const months& dm) noexcept; 5100b57cec5SDimitry Andricconstexpr year_month_weekday 5110b57cec5SDimitry Andric operator-(const year_month_weekday& ymwd, const years& dy) noexcept; 5120b57cec5SDimitry Andric 5130b57cec5SDimitry Andric// 25.8.17, class year_month_weekday_last // C++20 5140b57cec5SDimitry Andricclass year_month_weekday_last; 5150b57cec5SDimitry Andric 5160b57cec5SDimitry Andricconstexpr bool operator==(const year_month_weekday_last& x, 5170b57cec5SDimitry Andric const year_month_weekday_last& y) noexcept; 5180b57cec5SDimitry Andricconstexpr bool operator!=(const year_month_weekday_last& x, 5190b57cec5SDimitry Andric const year_month_weekday_last& y) noexcept; 5200b57cec5SDimitry Andricconstexpr year_month_weekday_last 5210b57cec5SDimitry Andric operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept; 5220b57cec5SDimitry Andricconstexpr year_month_weekday_last 5230b57cec5SDimitry Andric operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept; 5240b57cec5SDimitry Andricconstexpr year_month_weekday_last 5250b57cec5SDimitry Andric operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; 5260b57cec5SDimitry Andricconstexpr year_month_weekday_last 5270b57cec5SDimitry Andric operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; 5280b57cec5SDimitry Andricconstexpr year_month_weekday_last 5290b57cec5SDimitry Andric operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; 5300b57cec5SDimitry Andricconstexpr year_month_weekday_last 5310b57cec5SDimitry Andric operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; 5320b57cec5SDimitry Andric 5330b57cec5SDimitry Andric// 25.8.18, civil calendar conventional syntax operators // C++20 5340b57cec5SDimitry Andricconstexpr year_month 5350b57cec5SDimitry Andric operator/(const year& y, const month& m) noexcept; 5360b57cec5SDimitry Andricconstexpr year_month 5370b57cec5SDimitry Andric operator/(const year& y, int m) noexcept; 5380b57cec5SDimitry Andricconstexpr month_day 5390b57cec5SDimitry Andric operator/(const month& m, const day& d) noexcept; 5400b57cec5SDimitry Andricconstexpr month_day 5410b57cec5SDimitry Andric operator/(const month& m, int d) noexcept; 5420b57cec5SDimitry Andricconstexpr month_day 5430b57cec5SDimitry Andric operator/(int m, const day& d) noexcept; 5440b57cec5SDimitry Andricconstexpr month_day 5450b57cec5SDimitry Andric operator/(const day& d, const month& m) noexcept; 5460b57cec5SDimitry Andricconstexpr month_day 5470b57cec5SDimitry Andric operator/(const day& d, int m) noexcept; 5480b57cec5SDimitry Andricconstexpr month_day_last 5490b57cec5SDimitry Andric operator/(const month& m, last_spec) noexcept; 5500b57cec5SDimitry Andricconstexpr month_day_last 5510b57cec5SDimitry Andric operator/(int m, last_spec) noexcept; 5520b57cec5SDimitry Andricconstexpr month_day_last 5530b57cec5SDimitry Andric operator/(last_spec, const month& m) noexcept; 5540b57cec5SDimitry Andricconstexpr month_day_last 5550b57cec5SDimitry Andric operator/(last_spec, int m) noexcept; 5560b57cec5SDimitry Andricconstexpr month_weekday 5570b57cec5SDimitry Andric operator/(const month& m, const weekday_indexed& wdi) noexcept; 5580b57cec5SDimitry Andricconstexpr month_weekday 5590b57cec5SDimitry Andric operator/(int m, const weekday_indexed& wdi) noexcept; 5600b57cec5SDimitry Andricconstexpr month_weekday 5610b57cec5SDimitry Andric operator/(const weekday_indexed& wdi, const month& m) noexcept; 5620b57cec5SDimitry Andricconstexpr month_weekday 5630b57cec5SDimitry Andric operator/(const weekday_indexed& wdi, int m) noexcept; 5640b57cec5SDimitry Andricconstexpr month_weekday_last 5650b57cec5SDimitry Andric operator/(const month& m, const weekday_last& wdl) noexcept; 5660b57cec5SDimitry Andricconstexpr month_weekday_last 5670b57cec5SDimitry Andric operator/(int m, const weekday_last& wdl) noexcept; 5680b57cec5SDimitry Andricconstexpr month_weekday_last 5690b57cec5SDimitry Andric operator/(const weekday_last& wdl, const month& m) noexcept; 5700b57cec5SDimitry Andricconstexpr month_weekday_last 5710b57cec5SDimitry Andric operator/(const weekday_last& wdl, int m) noexcept; 5720b57cec5SDimitry Andricconstexpr year_month_day 5730b57cec5SDimitry Andric operator/(const year_month& ym, const day& d) noexcept; 5740b57cec5SDimitry Andricconstexpr year_month_day 5750b57cec5SDimitry Andric operator/(const year_month& ym, int d) noexcept; 5760b57cec5SDimitry Andricconstexpr year_month_day 5770b57cec5SDimitry Andric operator/(const year& y, const month_day& md) noexcept; 5780b57cec5SDimitry Andricconstexpr year_month_day 5790b57cec5SDimitry Andric operator/(int y, const month_day& md) noexcept; 5800b57cec5SDimitry Andricconstexpr year_month_day 5810b57cec5SDimitry Andric operator/(const month_day& md, const year& y) noexcept; 5820b57cec5SDimitry Andricconstexpr year_month_day 5830b57cec5SDimitry Andric operator/(const month_day& md, int y) noexcept; 5840b57cec5SDimitry Andricconstexpr year_month_day_last 5850b57cec5SDimitry Andric operator/(const year_month& ym, last_spec) noexcept; 5860b57cec5SDimitry Andricconstexpr year_month_day_last 5870b57cec5SDimitry Andric operator/(const year& y, const month_day_last& mdl) noexcept; 5880b57cec5SDimitry Andricconstexpr year_month_day_last 5890b57cec5SDimitry Andric operator/(int y, const month_day_last& mdl) noexcept; 5900b57cec5SDimitry Andricconstexpr year_month_day_last 5910b57cec5SDimitry Andric operator/(const month_day_last& mdl, const year& y) noexcept; 5920b57cec5SDimitry Andricconstexpr year_month_day_last 5930b57cec5SDimitry Andric operator/(const month_day_last& mdl, int y) noexcept; 5940b57cec5SDimitry Andricconstexpr year_month_weekday 5950b57cec5SDimitry Andric operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; 5960b57cec5SDimitry Andricconstexpr year_month_weekday 5970b57cec5SDimitry Andric operator/(const year& y, const month_weekday& mwd) noexcept; 5980b57cec5SDimitry Andricconstexpr year_month_weekday 5990b57cec5SDimitry Andric operator/(int y, const month_weekday& mwd) noexcept; 6000b57cec5SDimitry Andricconstexpr year_month_weekday 6010b57cec5SDimitry Andric operator/(const month_weekday& mwd, const year& y) noexcept; 6020b57cec5SDimitry Andricconstexpr year_month_weekday 6030b57cec5SDimitry Andric operator/(const month_weekday& mwd, int y) noexcept; 6040b57cec5SDimitry Andricconstexpr year_month_weekday_last 6050b57cec5SDimitry Andric operator/(const year_month& ym, const weekday_last& wdl) noexcept; 6060b57cec5SDimitry Andricconstexpr year_month_weekday_last 6070b57cec5SDimitry Andric operator/(const year& y, const month_weekday_last& mwdl) noexcept; 6080b57cec5SDimitry Andricconstexpr year_month_weekday_last 6090b57cec5SDimitry Andric operator/(int y, const month_weekday_last& mwdl) noexcept; 6100b57cec5SDimitry Andricconstexpr year_month_weekday_last 6110b57cec5SDimitry Andric operator/(const month_weekday_last& mwdl, const year& y) noexcept; 6120b57cec5SDimitry Andricconstexpr year_month_weekday_last 6130b57cec5SDimitry Andric operator/(const month_weekday_last& mwdl, int y) noexcept; 6140b57cec5SDimitry Andric 615*e40139ffSDimitry Andric// 26.9, class template hh_mm_ss 616*e40139ffSDimitry Andrictemplate <class Duration> 617*e40139ffSDimitry Andricclass hh_mm_ss 618*e40139ffSDimitry Andric{ 619*e40139ffSDimitry Andric bool is_neg; // exposition only 620*e40139ffSDimitry Andric chrono::hours h; // exposition only 621*e40139ffSDimitry Andric chrono::minutes m; // exposition only 622*e40139ffSDimitry Andric chrono::seconds s; // exposition only 623*e40139ffSDimitry Andric precision ss; // exposition only 6240b57cec5SDimitry Andric 625*e40139ffSDimitry Andricpublic: 626*e40139ffSDimitry Andric static unsigned constexpr fractional_width = see below; 627*e40139ffSDimitry Andric using precision = see below; 628*e40139ffSDimitry Andric 629*e40139ffSDimitry Andric constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {} 630*e40139ffSDimitry Andric constexpr explicit hh_mm_ss(Duration d) noexcept; 631*e40139ffSDimitry Andric 632*e40139ffSDimitry Andric constexpr bool is_negative() const noexcept; 633*e40139ffSDimitry Andric constexpr chrono::hours hours() const noexcept; 634*e40139ffSDimitry Andric constexpr chrono::minutes minutes() const noexcept; 635*e40139ffSDimitry Andric constexpr chrono::seconds seconds() const noexcept; 636*e40139ffSDimitry Andric constexpr precision subseconds() const noexcept; 637*e40139ffSDimitry Andric 638*e40139ffSDimitry Andric constexpr explicit operator precision() const noexcept; 639*e40139ffSDimitry Andric constexpr precision to_duration() const noexcept; 640*e40139ffSDimitry Andric}; 641*e40139ffSDimitry Andric 642*e40139ffSDimitry Andrictemplate <class charT, class traits, class Duration> 643*e40139ffSDimitry Andric basic_ostream<charT, traits>& 644*e40139ffSDimitry Andric operator<<(basic_ostream<charT, traits>& os, hh_mm_ss<Duration> const& hms); 645*e40139ffSDimitry Andric 646*e40139ffSDimitry Andric// 26.10, 12/24 hour functions 647*e40139ffSDimitry Andricconstexpr bool is_am(hours const& h) noexcept; 648*e40139ffSDimitry Andricconstexpr bool is_pm(hours const& h) noexcept; 649*e40139ffSDimitry Andricconstexpr hours make12(const hours& h) noexcept; 650*e40139ffSDimitry Andricconstexpr hours make24(const hours& h, bool is_pm) noexcept; 651*e40139ffSDimitry Andric 6520b57cec5SDimitry Andric 6530b57cec5SDimitry Andric// 25.10.2, time zone database // C++20 6540b57cec5SDimitry Andricstruct tzdb; 6550b57cec5SDimitry Andricclass tzdb_list; 6560b57cec5SDimitry Andric 6570b57cec5SDimitry Andric// 25.10.2.3, time zone database access // C++20 6580b57cec5SDimitry Andricconst tzdb& get_tzdb(); 6590b57cec5SDimitry Andrictzdb_list& get_tzdb_list(); 6600b57cec5SDimitry Andricconst time_zone* locate_zone(string_view tz_name); 6610b57cec5SDimitry Andricconst time_zone* current_zone(); 6620b57cec5SDimitry Andric 6630b57cec5SDimitry Andric// 25.10.2.4, remote time zone database support // C++20 6640b57cec5SDimitry Andricconst tzdb& reload_tzdb(); 6650b57cec5SDimitry Andricstring remote_version(); 6660b57cec5SDimitry Andric 6670b57cec5SDimitry Andric// 25.10.3, exception classes // C++20 6680b57cec5SDimitry Andricclass nonexistent_local_time; 6690b57cec5SDimitry Andricclass ambiguous_local_time; 6700b57cec5SDimitry Andric 6710b57cec5SDimitry Andric// 25.10.4, information classes // C++20 6720b57cec5SDimitry Andricstruct sys_info; 6730b57cec5SDimitry Andricstruct local_info; 6740b57cec5SDimitry Andric 6750b57cec5SDimitry Andric// 25.10.5, class time_zone // C++20 6760b57cec5SDimitry Andricenum class choose {earliest, latest}; 6770b57cec5SDimitry Andricclass time_zone; 6780b57cec5SDimitry Andricbool operator==(const time_zone& x, const time_zone& y) noexcept; 6790b57cec5SDimitry Andricbool operator!=(const time_zone& x, const time_zone& y) noexcept; 6800b57cec5SDimitry Andricbool operator<(const time_zone& x, const time_zone& y) noexcept; 6810b57cec5SDimitry Andricbool operator>(const time_zone& x, const time_zone& y) noexcept; 6820b57cec5SDimitry Andricbool operator<=(const time_zone& x, const time_zone& y) noexcept; 6830b57cec5SDimitry Andricbool operator>=(const time_zone& x, const time_zone& y) noexcept; 6840b57cec5SDimitry Andric 6850b57cec5SDimitry Andric// 25.10.6, class template zoned_traits // C++20 6860b57cec5SDimitry Andrictemplate<class T> struct zoned_traits; 6870b57cec5SDimitry Andric 6880b57cec5SDimitry Andric// 25.10.7, class template zoned_time // C++20 6890b57cec5SDimitry Andrictemplate<class Duration, class TimeZonePtr = const time_zone*> class zoned_time; 6900b57cec5SDimitry Andricusing zoned_seconds = zoned_time<seconds>; 6910b57cec5SDimitry Andric 6920b57cec5SDimitry Andrictemplate<class Duration1, class Duration2, class TimeZonePtr> 6930b57cec5SDimitry Andric bool operator==(const zoned_time<Duration1, TimeZonePtr>& x, 6940b57cec5SDimitry Andric const zoned_time<Duration2, TimeZonePtr>& y); 6950b57cec5SDimitry Andrictemplate<class Duration1, class Duration2, class TimeZonePtr> 6960b57cec5SDimitry Andric bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x, 6970b57cec5SDimitry Andric const zoned_time<Duration2, TimeZonePtr>& y); 6980b57cec5SDimitry Andric 6990b57cec5SDimitry Andric// 25.10.8, leap second support // C++20 7000b57cec5SDimitry Andricclass leap; 7010b57cec5SDimitry Andric 7020b57cec5SDimitry Andricbool operator==(const leap& x, const leap& y); 7030b57cec5SDimitry Andricbool operator!=(const leap& x, const leap& y); 7040b57cec5SDimitry Andricbool operator< (const leap& x, const leap& y); 7050b57cec5SDimitry Andricbool operator> (const leap& x, const leap& y); 7060b57cec5SDimitry Andricbool operator<=(const leap& x, const leap& y); 7070b57cec5SDimitry Andricbool operator>=(const leap& x, const leap& y); 7080b57cec5SDimitry Andrictemplate<class Duration> 7090b57cec5SDimitry Andric bool operator==(const leap& x, const sys_time<Duration>& y); 7100b57cec5SDimitry Andrictemplate<class Duration> 7110b57cec5SDimitry Andric bool operator==(const sys_time<Duration>& x, const leap& y); 7120b57cec5SDimitry Andrictemplate<class Duration> 7130b57cec5SDimitry Andric bool operator!=(const leap& x, const sys_time<Duration>& y); 7140b57cec5SDimitry Andrictemplate<class Duration> 7150b57cec5SDimitry Andric bool operator!=(const sys_time<Duration>& x, const leap& y); 7160b57cec5SDimitry Andrictemplate<class Duration> 7170b57cec5SDimitry Andric bool operator< (const leap& x, const sys_time<Duration>& y); 7180b57cec5SDimitry Andrictemplate<class Duration> 7190b57cec5SDimitry Andric bool operator< (const sys_time<Duration>& x, const leap& y); 7200b57cec5SDimitry Andrictemplate<class Duration> 7210b57cec5SDimitry Andric bool operator> (const leap& x, const sys_time<Duration>& y); 7220b57cec5SDimitry Andrictemplate<class Duration> 7230b57cec5SDimitry Andric bool operator> (const sys_time<Duration>& x, const leap& y); 7240b57cec5SDimitry Andrictemplate<class Duration> 7250b57cec5SDimitry Andric bool operator<=(const leap& x, const sys_time<Duration>& y); 7260b57cec5SDimitry Andrictemplate<class Duration> 7270b57cec5SDimitry Andric bool operator<=(const sys_time<Duration>& x, const leap& y); 7280b57cec5SDimitry Andrictemplate<class Duration> 7290b57cec5SDimitry Andric bool operator>=(const leap& x, const sys_time<Duration>& y); 7300b57cec5SDimitry Andrictemplate<class Duration> 7310b57cec5SDimitry Andric bool operator>=(const sys_time<Duration>& x, const leap& y); 7320b57cec5SDimitry Andric 7330b57cec5SDimitry Andric// 25.10.9, class link // C++20 7340b57cec5SDimitry Andricclass link; 7350b57cec5SDimitry Andricbool operator==(const link& x, const link& y); 7360b57cec5SDimitry Andricbool operator!=(const link& x, const link& y); 7370b57cec5SDimitry Andricbool operator< (const link& x, const link& y); 7380b57cec5SDimitry Andricbool operator> (const link& x, const link& y); 7390b57cec5SDimitry Andricbool operator<=(const link& x, const link& y); 7400b57cec5SDimitry Andricbool operator>=(const link& x, const link& y); 7410b57cec5SDimitry Andric 7420b57cec5SDimitry Andric// 25.11, formatting // C++20 7430b57cec5SDimitry Andrictemplate<class charT, class Streamable> 7440b57cec5SDimitry Andric basic_string<charT> 7450b57cec5SDimitry Andric format(const charT* fmt, const Streamable& s); 7460b57cec5SDimitry Andric 7470b57cec5SDimitry Andrictemplate<class charT, class Streamable> 7480b57cec5SDimitry Andric basic_string<charT> 7490b57cec5SDimitry Andric format(const locale& loc, const charT* fmt, const Streamable& s); 7500b57cec5SDimitry Andric 7510b57cec5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Streamable> 7520b57cec5SDimitry Andric basic_string<charT, traits, Alloc> 7530b57cec5SDimitry Andric format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s); 7540b57cec5SDimitry Andric 7550b57cec5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Streamable> 7560b57cec5SDimitry Andric basic_string<charT, traits, Alloc> 7570b57cec5SDimitry Andric format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt, 7580b57cec5SDimitry Andric const Streamable& s); 7590b57cec5SDimitry Andric 7600b57cec5SDimitry Andric// 25.12, parsing // C++20 7610b57cec5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Parsable> 7620b57cec5SDimitry Andricunspecified 7630b57cec5SDimitry Andric parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp); 7640b57cec5SDimitry Andric 7650b57cec5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Parsable> 7660b57cec5SDimitry Andricunspecified 7670b57cec5SDimitry Andric parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, 7680b57cec5SDimitry Andric basic_string<charT, traits, Alloc>& abbrev); 7690b57cec5SDimitry Andric 7700b57cec5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Parsable> 7710b57cec5SDimitry Andricunspecified 7720b57cec5SDimitry Andric parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, 7730b57cec5SDimitry Andric minutes& offset); 7740b57cec5SDimitry Andric 7750b57cec5SDimitry Andrictemplate<class charT, class traits, class Alloc, class Parsable> 7760b57cec5SDimitry Andricunspecified 7770b57cec5SDimitry Andric parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp, 7780b57cec5SDimitry Andric basic_string<charT, traits, Alloc>& abbrev, minutes& offset); 7790b57cec5SDimitry Andric 7800b57cec5SDimitry Andric// calendrical constants 7810b57cec5SDimitry Andricinline constexpr last_spec last{}; // C++20 7820b57cec5SDimitry Andricinline constexpr chrono::weekday Sunday{0}; // C++20 7830b57cec5SDimitry Andricinline constexpr chrono::weekday Monday{1}; // C++20 7840b57cec5SDimitry Andricinline constexpr chrono::weekday Tuesday{2}; // C++20 7850b57cec5SDimitry Andricinline constexpr chrono::weekday Wednesday{3}; // C++20 7860b57cec5SDimitry Andricinline constexpr chrono::weekday Thursday{4}; // C++20 7870b57cec5SDimitry Andricinline constexpr chrono::weekday Friday{5}; // C++20 7880b57cec5SDimitry Andricinline constexpr chrono::weekday Saturday{6}; // C++20 7890b57cec5SDimitry Andric 7900b57cec5SDimitry Andricinline constexpr chrono::month January{1}; // C++20 7910b57cec5SDimitry Andricinline constexpr chrono::month February{2}; // C++20 7920b57cec5SDimitry Andricinline constexpr chrono::month March{3}; // C++20 7930b57cec5SDimitry Andricinline constexpr chrono::month April{4}; // C++20 7940b57cec5SDimitry Andricinline constexpr chrono::month May{5}; // C++20 7950b57cec5SDimitry Andricinline constexpr chrono::month June{6}; // C++20 7960b57cec5SDimitry Andricinline constexpr chrono::month July{7}; // C++20 7970b57cec5SDimitry Andricinline constexpr chrono::month August{8}; // C++20 7980b57cec5SDimitry Andricinline constexpr chrono::month September{9}; // C++20 7990b57cec5SDimitry Andricinline constexpr chrono::month October{10}; // C++20 8000b57cec5SDimitry Andricinline constexpr chrono::month November{11}; // C++20 8010b57cec5SDimitry Andricinline constexpr chrono::month December{12}; // C++20 8020b57cec5SDimitry Andric} // chrono 8030b57cec5SDimitry Andric 8040b57cec5SDimitry Andricinline namespace literals { 8050b57cec5SDimitry Andric inline namespace chrono_literals { 8060b57cec5SDimitry Andricconstexpr chrono::hours operator ""h(unsigned long long); // C++14 8070b57cec5SDimitry Andricconstexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14 8080b57cec5SDimitry Andricconstexpr chrono::minutes operator ""min(unsigned long long); // C++14 8090b57cec5SDimitry Andricconstexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14 8100b57cec5SDimitry Andricconstexpr chrono::seconds operator ""s(unsigned long long); // C++14 8110b57cec5SDimitry Andricconstexpr chrono::duration<unspecified > operator ""s(long double); // C++14 8120b57cec5SDimitry Andricconstexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 8130b57cec5SDimitry Andricconstexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14 8140b57cec5SDimitry Andricconstexpr chrono::microseconds operator ""us(unsigned long long); // C++14 8150b57cec5SDimitry Andricconstexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14 8160b57cec5SDimitry Andricconstexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 8170b57cec5SDimitry Andricconstexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14 8180b57cec5SDimitry Andricconstexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20 8190b57cec5SDimitry Andricconstexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20 8200b57cec5SDimitry Andric} // chrono_literals 8210b57cec5SDimitry Andric} // literals 8220b57cec5SDimitry Andric 8230b57cec5SDimitry Andric} // std 8240b57cec5SDimitry Andric*/ 8250b57cec5SDimitry Andric 8260b57cec5SDimitry Andric#include <__config> 8270b57cec5SDimitry Andric#include <ctime> 8280b57cec5SDimitry Andric#include <type_traits> 8290b57cec5SDimitry Andric#include <ratio> 8300b57cec5SDimitry Andric#include <limits> 8310b57cec5SDimitry Andric#include <version> 8320b57cec5SDimitry Andric 8330b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 8340b57cec5SDimitry Andric#pragma GCC system_header 8350b57cec5SDimitry Andric#endif 8360b57cec5SDimitry Andric 8370b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 8380b57cec5SDimitry Andric#include <__undef_macros> 8390b57cec5SDimitry Andric 8400b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 8410b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM 8420b57cec5SDimitry Andricstruct _FilesystemClock; 8430b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_FILESYSTEM 8440b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 8450b57cec5SDimitry Andric 8460b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 8470b57cec5SDimitry Andric 8480b57cec5SDimitry Andricnamespace chrono 8490b57cec5SDimitry Andric{ 8500b57cec5SDimitry Andric 8510b57cec5SDimitry Andrictemplate <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration; 8520b57cec5SDimitry Andric 8530b57cec5SDimitry Andrictemplate <class _Tp> 8540b57cec5SDimitry Andricstruct __is_duration : false_type {}; 8550b57cec5SDimitry Andric 8560b57cec5SDimitry Andrictemplate <class _Rep, class _Period> 8570b57cec5SDimitry Andricstruct __is_duration<duration<_Rep, _Period> > : true_type {}; 8580b57cec5SDimitry Andric 8590b57cec5SDimitry Andrictemplate <class _Rep, class _Period> 8600b57cec5SDimitry Andricstruct __is_duration<const duration<_Rep, _Period> > : true_type {}; 8610b57cec5SDimitry Andric 8620b57cec5SDimitry Andrictemplate <class _Rep, class _Period> 8630b57cec5SDimitry Andricstruct __is_duration<volatile duration<_Rep, _Period> > : true_type {}; 8640b57cec5SDimitry Andric 8650b57cec5SDimitry Andrictemplate <class _Rep, class _Period> 8660b57cec5SDimitry Andricstruct __is_duration<const volatile duration<_Rep, _Period> > : true_type {}; 8670b57cec5SDimitry Andric 8680b57cec5SDimitry Andric} // chrono 8690b57cec5SDimitry Andric 8700b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 8710b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>, 8720b57cec5SDimitry Andric chrono::duration<_Rep2, _Period2> > 8730b57cec5SDimitry Andric{ 8740b57cec5SDimitry Andric typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type, 8750b57cec5SDimitry Andric typename __ratio_gcd<_Period1, _Period2>::type> type; 8760b57cec5SDimitry Andric}; 8770b57cec5SDimitry Andric 8780b57cec5SDimitry Andricnamespace chrono { 8790b57cec5SDimitry Andric 8800b57cec5SDimitry Andric// duration_cast 8810b57cec5SDimitry Andric 8820b57cec5SDimitry Andrictemplate <class _FromDuration, class _ToDuration, 8830b57cec5SDimitry Andric class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type, 8840b57cec5SDimitry Andric bool = _Period::num == 1, 8850b57cec5SDimitry Andric bool = _Period::den == 1> 8860b57cec5SDimitry Andricstruct __duration_cast; 8870b57cec5SDimitry Andric 8880b57cec5SDimitry Andrictemplate <class _FromDuration, class _ToDuration, class _Period> 8890b57cec5SDimitry Andricstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, true> 8900b57cec5SDimitry Andric{ 8910b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 8920b57cec5SDimitry Andric _ToDuration operator()(const _FromDuration& __fd) const 8930b57cec5SDimitry Andric { 8940b57cec5SDimitry Andric return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count())); 8950b57cec5SDimitry Andric } 8960b57cec5SDimitry Andric}; 8970b57cec5SDimitry Andric 8980b57cec5SDimitry Andrictemplate <class _FromDuration, class _ToDuration, class _Period> 8990b57cec5SDimitry Andricstruct __duration_cast<_FromDuration, _ToDuration, _Period, true, false> 9000b57cec5SDimitry Andric{ 9010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 9020b57cec5SDimitry Andric _ToDuration operator()(const _FromDuration& __fd) const 9030b57cec5SDimitry Andric { 9040b57cec5SDimitry Andric typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 9050b57cec5SDimitry Andric return _ToDuration(static_cast<typename _ToDuration::rep>( 9060b57cec5SDimitry Andric static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den))); 9070b57cec5SDimitry Andric } 9080b57cec5SDimitry Andric}; 9090b57cec5SDimitry Andric 9100b57cec5SDimitry Andrictemplate <class _FromDuration, class _ToDuration, class _Period> 9110b57cec5SDimitry Andricstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, true> 9120b57cec5SDimitry Andric{ 9130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 9140b57cec5SDimitry Andric _ToDuration operator()(const _FromDuration& __fd) const 9150b57cec5SDimitry Andric { 9160b57cec5SDimitry Andric typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 9170b57cec5SDimitry Andric return _ToDuration(static_cast<typename _ToDuration::rep>( 9180b57cec5SDimitry Andric static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num))); 9190b57cec5SDimitry Andric } 9200b57cec5SDimitry Andric}; 9210b57cec5SDimitry Andric 9220b57cec5SDimitry Andrictemplate <class _FromDuration, class _ToDuration, class _Period> 9230b57cec5SDimitry Andricstruct __duration_cast<_FromDuration, _ToDuration, _Period, false, false> 9240b57cec5SDimitry Andric{ 9250b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 9260b57cec5SDimitry Andric _ToDuration operator()(const _FromDuration& __fd) const 9270b57cec5SDimitry Andric { 9280b57cec5SDimitry Andric typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct; 9290b57cec5SDimitry Andric return _ToDuration(static_cast<typename _ToDuration::rep>( 9300b57cec5SDimitry Andric static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num) 9310b57cec5SDimitry Andric / static_cast<_Ct>(_Period::den))); 9320b57cec5SDimitry Andric } 9330b57cec5SDimitry Andric}; 9340b57cec5SDimitry Andric 9350b57cec5SDimitry Andrictemplate <class _ToDuration, class _Rep, class _Period> 9360b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 9370b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 9380b57cec5SDimitry Andrictypename enable_if 9390b57cec5SDimitry Andric< 9400b57cec5SDimitry Andric __is_duration<_ToDuration>::value, 9410b57cec5SDimitry Andric _ToDuration 9420b57cec5SDimitry Andric>::type 9430b57cec5SDimitry Andricduration_cast(const duration<_Rep, _Period>& __fd) 9440b57cec5SDimitry Andric{ 9450b57cec5SDimitry Andric return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd); 9460b57cec5SDimitry Andric} 9470b57cec5SDimitry Andric 9480b57cec5SDimitry Andrictemplate <class _Rep> 9490b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {}; 9500b57cec5SDimitry Andric 9510b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) 9520b57cec5SDimitry Andrictemplate <class _Rep> 9530b57cec5SDimitry Andric_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v 9540b57cec5SDimitry Andric = treat_as_floating_point<_Rep>::value; 9550b57cec5SDimitry Andric#endif 9560b57cec5SDimitry Andric 9570b57cec5SDimitry Andrictemplate <class _Rep> 9580b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS duration_values 9590b57cec5SDimitry Andric{ 9600b57cec5SDimitry Andricpublic: 9610b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);} 9620b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT {return numeric_limits<_Rep>::max();} 9630b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT {return numeric_limits<_Rep>::lowest();} 9640b57cec5SDimitry Andric}; 9650b57cec5SDimitry Andric 9660b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 9670b57cec5SDimitry Andrictemplate <class _ToDuration, class _Rep, class _Period> 9680b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 9690b57cec5SDimitry Andrictypename enable_if 9700b57cec5SDimitry Andric< 9710b57cec5SDimitry Andric __is_duration<_ToDuration>::value, 9720b57cec5SDimitry Andric _ToDuration 9730b57cec5SDimitry Andric>::type 9740b57cec5SDimitry Andricfloor(const duration<_Rep, _Period>& __d) 9750b57cec5SDimitry Andric{ 9760b57cec5SDimitry Andric _ToDuration __t = duration_cast<_ToDuration>(__d); 9770b57cec5SDimitry Andric if (__t > __d) 9780b57cec5SDimitry Andric __t = __t - _ToDuration{1}; 9790b57cec5SDimitry Andric return __t; 9800b57cec5SDimitry Andric} 9810b57cec5SDimitry Andric 9820b57cec5SDimitry Andrictemplate <class _ToDuration, class _Rep, class _Period> 9830b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 9840b57cec5SDimitry Andrictypename enable_if 9850b57cec5SDimitry Andric< 9860b57cec5SDimitry Andric __is_duration<_ToDuration>::value, 9870b57cec5SDimitry Andric _ToDuration 9880b57cec5SDimitry Andric>::type 9890b57cec5SDimitry Andricceil(const duration<_Rep, _Period>& __d) 9900b57cec5SDimitry Andric{ 9910b57cec5SDimitry Andric _ToDuration __t = duration_cast<_ToDuration>(__d); 9920b57cec5SDimitry Andric if (__t < __d) 9930b57cec5SDimitry Andric __t = __t + _ToDuration{1}; 9940b57cec5SDimitry Andric return __t; 9950b57cec5SDimitry Andric} 9960b57cec5SDimitry Andric 9970b57cec5SDimitry Andrictemplate <class _ToDuration, class _Rep, class _Period> 9980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 9990b57cec5SDimitry Andrictypename enable_if 10000b57cec5SDimitry Andric< 10010b57cec5SDimitry Andric __is_duration<_ToDuration>::value, 10020b57cec5SDimitry Andric _ToDuration 10030b57cec5SDimitry Andric>::type 10040b57cec5SDimitry Andricround(const duration<_Rep, _Period>& __d) 10050b57cec5SDimitry Andric{ 10060b57cec5SDimitry Andric _ToDuration __lower = floor<_ToDuration>(__d); 10070b57cec5SDimitry Andric _ToDuration __upper = __lower + _ToDuration{1}; 10080b57cec5SDimitry Andric auto __lowerDiff = __d - __lower; 10090b57cec5SDimitry Andric auto __upperDiff = __upper - __d; 10100b57cec5SDimitry Andric if (__lowerDiff < __upperDiff) 10110b57cec5SDimitry Andric return __lower; 10120b57cec5SDimitry Andric if (__lowerDiff > __upperDiff) 10130b57cec5SDimitry Andric return __upper; 10140b57cec5SDimitry Andric return __lower.count() & 1 ? __upper : __lower; 10150b57cec5SDimitry Andric} 10160b57cec5SDimitry Andric#endif 10170b57cec5SDimitry Andric 10180b57cec5SDimitry Andric// duration 10190b57cec5SDimitry Andric 10200b57cec5SDimitry Andrictemplate <class _Rep, class _Period> 10210b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS duration 10220b57cec5SDimitry Andric{ 10230b57cec5SDimitry Andric static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration"); 10240b57cec5SDimitry Andric static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio"); 10250b57cec5SDimitry Andric static_assert(_Period::num > 0, "duration period must be positive"); 10260b57cec5SDimitry Andric 10270b57cec5SDimitry Andric template <class _R1, class _R2> 10280b57cec5SDimitry Andric struct __no_overflow 10290b57cec5SDimitry Andric { 10300b57cec5SDimitry Andric private: 10310b57cec5SDimitry Andric static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value; 10320b57cec5SDimitry Andric static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value; 10330b57cec5SDimitry Andric static const intmax_t __n1 = _R1::num / __gcd_n1_n2; 10340b57cec5SDimitry Andric static const intmax_t __d1 = _R1::den / __gcd_d1_d2; 10350b57cec5SDimitry Andric static const intmax_t __n2 = _R2::num / __gcd_n1_n2; 10360b57cec5SDimitry Andric static const intmax_t __d2 = _R2::den / __gcd_d1_d2; 10370b57cec5SDimitry Andric static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1); 10380b57cec5SDimitry Andric 10390b57cec5SDimitry Andric template <intmax_t _Xp, intmax_t _Yp, bool __overflow> 10400b57cec5SDimitry Andric struct __mul // __overflow == false 10410b57cec5SDimitry Andric { 10420b57cec5SDimitry Andric static const intmax_t value = _Xp * _Yp; 10430b57cec5SDimitry Andric }; 10440b57cec5SDimitry Andric 10450b57cec5SDimitry Andric template <intmax_t _Xp, intmax_t _Yp> 10460b57cec5SDimitry Andric struct __mul<_Xp, _Yp, true> 10470b57cec5SDimitry Andric { 10480b57cec5SDimitry Andric static const intmax_t value = 1; 10490b57cec5SDimitry Andric }; 10500b57cec5SDimitry Andric 10510b57cec5SDimitry Andric public: 10520b57cec5SDimitry Andric static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1); 10530b57cec5SDimitry Andric typedef ratio<__mul<__n1, __d2, !value>::value, 10540b57cec5SDimitry Andric __mul<__n2, __d1, !value>::value> type; 10550b57cec5SDimitry Andric }; 10560b57cec5SDimitry Andric 10570b57cec5SDimitry Andricpublic: 10580b57cec5SDimitry Andric typedef _Rep rep; 10590b57cec5SDimitry Andric typedef typename _Period::type period; 10600b57cec5SDimitry Andricprivate: 10610b57cec5SDimitry Andric rep __rep_; 10620b57cec5SDimitry Andricpublic: 10630b57cec5SDimitry Andric 10640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 10650b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 10660b57cec5SDimitry Andric duration() = default; 10670b57cec5SDimitry Andric#else 10680b57cec5SDimitry Andric duration() {} 10690b57cec5SDimitry Andric#endif 10700b57cec5SDimitry Andric 10710b57cec5SDimitry Andric template <class _Rep2> 10720b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 10730b57cec5SDimitry Andric explicit duration(const _Rep2& __r, 10740b57cec5SDimitry Andric typename enable_if 10750b57cec5SDimitry Andric < 10760b57cec5SDimitry Andric is_convertible<_Rep2, rep>::value && 10770b57cec5SDimitry Andric (treat_as_floating_point<rep>::value || 10780b57cec5SDimitry Andric !treat_as_floating_point<_Rep2>::value) 10790b57cec5SDimitry Andric >::type* = 0) 10800b57cec5SDimitry Andric : __rep_(__r) {} 10810b57cec5SDimitry Andric 10820b57cec5SDimitry Andric // conversions 10830b57cec5SDimitry Andric template <class _Rep2, class _Period2> 10840b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 10850b57cec5SDimitry Andric duration(const duration<_Rep2, _Period2>& __d, 10860b57cec5SDimitry Andric typename enable_if 10870b57cec5SDimitry Andric < 10880b57cec5SDimitry Andric __no_overflow<_Period2, period>::value && ( 10890b57cec5SDimitry Andric treat_as_floating_point<rep>::value || 10900b57cec5SDimitry Andric (__no_overflow<_Period2, period>::type::den == 1 && 10910b57cec5SDimitry Andric !treat_as_floating_point<_Rep2>::value)) 10920b57cec5SDimitry Andric >::type* = 0) 10930b57cec5SDimitry Andric : __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {} 10940b57cec5SDimitry Andric 10950b57cec5SDimitry Andric // observer 10960b57cec5SDimitry Andric 10970b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;} 10980b57cec5SDimitry Andric 10990b57cec5SDimitry Andric // arithmetic 11000b57cec5SDimitry Andric 11010b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);} 11020b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);} 11030b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;} 11040b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);} 11050b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;} 11060b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);} 11070b57cec5SDimitry Andric 11080b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;} 11090b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;} 11100b57cec5SDimitry Andric 11110b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;} 11120b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;} 11130b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;} 11140b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;} 11150b57cec5SDimitry Andric 11160b57cec5SDimitry Andric // special values 11170b57cec5SDimitry Andric 11180b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());} 11190b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {return duration(duration_values<rep>::min());} 11200b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {return duration(duration_values<rep>::max());} 11210b57cec5SDimitry Andric}; 11220b57cec5SDimitry Andric 11230b57cec5SDimitry Andrictypedef duration<long long, nano> nanoseconds; 11240b57cec5SDimitry Andrictypedef duration<long long, micro> microseconds; 11250b57cec5SDimitry Andrictypedef duration<long long, milli> milliseconds; 11260b57cec5SDimitry Andrictypedef duration<long long > seconds; 11270b57cec5SDimitry Andrictypedef duration< long, ratio< 60> > minutes; 11280b57cec5SDimitry Andrictypedef duration< long, ratio<3600> > hours; 11290b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 11300b57cec5SDimitry Andrictypedef duration< int, ratio_multiply<ratio<24>, hours::period>> days; 11310b57cec5SDimitry Andrictypedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks; 11320b57cec5SDimitry Andrictypedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years; 11330b57cec5SDimitry Andrictypedef duration< int, ratio_divide<years::period, ratio<12>>> months; 11340b57cec5SDimitry Andric#endif 11350b57cec5SDimitry Andric// Duration == 11360b57cec5SDimitry Andric 11370b57cec5SDimitry Andrictemplate <class _LhsDuration, class _RhsDuration> 11380b57cec5SDimitry Andricstruct __duration_eq 11390b57cec5SDimitry Andric{ 11400b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 11410b57cec5SDimitry Andric bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const 11420b57cec5SDimitry Andric { 11430b57cec5SDimitry Andric typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; 11440b57cec5SDimitry Andric return _Ct(__lhs).count() == _Ct(__rhs).count(); 11450b57cec5SDimitry Andric } 11460b57cec5SDimitry Andric}; 11470b57cec5SDimitry Andric 11480b57cec5SDimitry Andrictemplate <class _LhsDuration> 11490b57cec5SDimitry Andricstruct __duration_eq<_LhsDuration, _LhsDuration> 11500b57cec5SDimitry Andric{ 11510b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 11520b57cec5SDimitry Andric bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const 11530b57cec5SDimitry Andric {return __lhs.count() == __rhs.count();} 11540b57cec5SDimitry Andric}; 11550b57cec5SDimitry Andric 11560b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 11570b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 11580b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 11590b57cec5SDimitry Andricbool 11600b57cec5SDimitry Andricoperator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 11610b57cec5SDimitry Andric{ 11620b57cec5SDimitry Andric return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); 11630b57cec5SDimitry Andric} 11640b57cec5SDimitry Andric 11650b57cec5SDimitry Andric// Duration != 11660b57cec5SDimitry Andric 11670b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 11680b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 11690b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 11700b57cec5SDimitry Andricbool 11710b57cec5SDimitry Andricoperator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 11720b57cec5SDimitry Andric{ 11730b57cec5SDimitry Andric return !(__lhs == __rhs); 11740b57cec5SDimitry Andric} 11750b57cec5SDimitry Andric 11760b57cec5SDimitry Andric// Duration < 11770b57cec5SDimitry Andric 11780b57cec5SDimitry Andrictemplate <class _LhsDuration, class _RhsDuration> 11790b57cec5SDimitry Andricstruct __duration_lt 11800b57cec5SDimitry Andric{ 11810b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 11820b57cec5SDimitry Andric bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const 11830b57cec5SDimitry Andric { 11840b57cec5SDimitry Andric typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct; 11850b57cec5SDimitry Andric return _Ct(__lhs).count() < _Ct(__rhs).count(); 11860b57cec5SDimitry Andric } 11870b57cec5SDimitry Andric}; 11880b57cec5SDimitry Andric 11890b57cec5SDimitry Andrictemplate <class _LhsDuration> 11900b57cec5SDimitry Andricstruct __duration_lt<_LhsDuration, _LhsDuration> 11910b57cec5SDimitry Andric{ 11920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 11930b57cec5SDimitry Andric bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const 11940b57cec5SDimitry Andric {return __lhs.count() < __rhs.count();} 11950b57cec5SDimitry Andric}; 11960b57cec5SDimitry Andric 11970b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 11980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 11990b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 12000b57cec5SDimitry Andricbool 12010b57cec5SDimitry Andricoperator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 12020b57cec5SDimitry Andric{ 12030b57cec5SDimitry Andric return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs); 12040b57cec5SDimitry Andric} 12050b57cec5SDimitry Andric 12060b57cec5SDimitry Andric// Duration > 12070b57cec5SDimitry Andric 12080b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 12090b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12100b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 12110b57cec5SDimitry Andricbool 12120b57cec5SDimitry Andricoperator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 12130b57cec5SDimitry Andric{ 12140b57cec5SDimitry Andric return __rhs < __lhs; 12150b57cec5SDimitry Andric} 12160b57cec5SDimitry Andric 12170b57cec5SDimitry Andric// Duration <= 12180b57cec5SDimitry Andric 12190b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 12200b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12210b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 12220b57cec5SDimitry Andricbool 12230b57cec5SDimitry Andricoperator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 12240b57cec5SDimitry Andric{ 12250b57cec5SDimitry Andric return !(__rhs < __lhs); 12260b57cec5SDimitry Andric} 12270b57cec5SDimitry Andric 12280b57cec5SDimitry Andric// Duration >= 12290b57cec5SDimitry Andric 12300b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 12310b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12320b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 12330b57cec5SDimitry Andricbool 12340b57cec5SDimitry Andricoperator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 12350b57cec5SDimitry Andric{ 12360b57cec5SDimitry Andric return !(__lhs < __rhs); 12370b57cec5SDimitry Andric} 12380b57cec5SDimitry Andric 12390b57cec5SDimitry Andric// Duration + 12400b57cec5SDimitry Andric 12410b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 12420b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12430b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 12440b57cec5SDimitry Andrictypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 12450b57cec5SDimitry Andricoperator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 12460b57cec5SDimitry Andric{ 12470b57cec5SDimitry Andric typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; 12480b57cec5SDimitry Andric return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count()); 12490b57cec5SDimitry Andric} 12500b57cec5SDimitry Andric 12510b57cec5SDimitry Andric// Duration - 12520b57cec5SDimitry Andric 12530b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 12540b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12550b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 12560b57cec5SDimitry Andrictypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 12570b57cec5SDimitry Andricoperator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 12580b57cec5SDimitry Andric{ 12590b57cec5SDimitry Andric typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; 12600b57cec5SDimitry Andric return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count()); 12610b57cec5SDimitry Andric} 12620b57cec5SDimitry Andric 12630b57cec5SDimitry Andric// Duration * 12640b57cec5SDimitry Andric 12650b57cec5SDimitry Andrictemplate <class _Rep1, class _Period, class _Rep2> 12660b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12670b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 12680b57cec5SDimitry Andrictypename enable_if 12690b57cec5SDimitry Andric< 12700b57cec5SDimitry Andric is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, 12710b57cec5SDimitry Andric duration<typename common_type<_Rep1, _Rep2>::type, _Period> 12720b57cec5SDimitry Andric>::type 12730b57cec5SDimitry Andricoperator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 12740b57cec5SDimitry Andric{ 12750b57cec5SDimitry Andric typedef typename common_type<_Rep1, _Rep2>::type _Cr; 12760b57cec5SDimitry Andric typedef duration<_Cr, _Period> _Cd; 12770b57cec5SDimitry Andric return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s)); 12780b57cec5SDimitry Andric} 12790b57cec5SDimitry Andric 12800b57cec5SDimitry Andrictemplate <class _Rep1, class _Period, class _Rep2> 12810b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12820b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 12830b57cec5SDimitry Andrictypename enable_if 12840b57cec5SDimitry Andric< 12850b57cec5SDimitry Andric is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value, 12860b57cec5SDimitry Andric duration<typename common_type<_Rep1, _Rep2>::type, _Period> 12870b57cec5SDimitry Andric>::type 12880b57cec5SDimitry Andricoperator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d) 12890b57cec5SDimitry Andric{ 12900b57cec5SDimitry Andric return __d * __s; 12910b57cec5SDimitry Andric} 12920b57cec5SDimitry Andric 12930b57cec5SDimitry Andric// Duration / 12940b57cec5SDimitry Andric 12950b57cec5SDimitry Andrictemplate <class _Rep1, class _Period, class _Rep2> 12960b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 12970b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 12980b57cec5SDimitry Andrictypename enable_if 12990b57cec5SDimitry Andric< 13000b57cec5SDimitry Andric !__is_duration<_Rep2>::value && 13010b57cec5SDimitry Andric is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, 13020b57cec5SDimitry Andric duration<typename common_type<_Rep1, _Rep2>::type, _Period> 13030b57cec5SDimitry Andric>::type 13040b57cec5SDimitry Andricoperator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 13050b57cec5SDimitry Andric{ 13060b57cec5SDimitry Andric typedef typename common_type<_Rep1, _Rep2>::type _Cr; 13070b57cec5SDimitry Andric typedef duration<_Cr, _Period> _Cd; 13080b57cec5SDimitry Andric return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s)); 13090b57cec5SDimitry Andric} 13100b57cec5SDimitry Andric 13110b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 13120b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13130b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 13140b57cec5SDimitry Andrictypename common_type<_Rep1, _Rep2>::type 13150b57cec5SDimitry Andricoperator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 13160b57cec5SDimitry Andric{ 13170b57cec5SDimitry Andric typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct; 13180b57cec5SDimitry Andric return _Ct(__lhs).count() / _Ct(__rhs).count(); 13190b57cec5SDimitry Andric} 13200b57cec5SDimitry Andric 13210b57cec5SDimitry Andric// Duration % 13220b57cec5SDimitry Andric 13230b57cec5SDimitry Andrictemplate <class _Rep1, class _Period, class _Rep2> 13240b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13250b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 13260b57cec5SDimitry Andrictypename enable_if 13270b57cec5SDimitry Andric< 13280b57cec5SDimitry Andric !__is_duration<_Rep2>::value && 13290b57cec5SDimitry Andric is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value, 13300b57cec5SDimitry Andric duration<typename common_type<_Rep1, _Rep2>::type, _Period> 13310b57cec5SDimitry Andric>::type 13320b57cec5SDimitry Andricoperator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s) 13330b57cec5SDimitry Andric{ 13340b57cec5SDimitry Andric typedef typename common_type<_Rep1, _Rep2>::type _Cr; 13350b57cec5SDimitry Andric typedef duration<_Cr, _Period> _Cd; 13360b57cec5SDimitry Andric return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s)); 13370b57cec5SDimitry Andric} 13380b57cec5SDimitry Andric 13390b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Rep2, class _Period2> 13400b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY 13410b57cec5SDimitry Andric_LIBCPP_CONSTEXPR 13420b57cec5SDimitry Andrictypename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type 13430b57cec5SDimitry Andricoperator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 13440b57cec5SDimitry Andric{ 13450b57cec5SDimitry Andric typedef typename common_type<_Rep1, _Rep2>::type _Cr; 13460b57cec5SDimitry Andric typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd; 13470b57cec5SDimitry Andric return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count())); 13480b57cec5SDimitry Andric} 13490b57cec5SDimitry Andric 13500b57cec5SDimitry Andric////////////////////////////////////////////////////////// 13510b57cec5SDimitry Andric///////////////////// time_point ///////////////////////// 13520b57cec5SDimitry Andric////////////////////////////////////////////////////////// 13530b57cec5SDimitry Andric 13540b57cec5SDimitry Andrictemplate <class _Clock, class _Duration = typename _Clock::duration> 13550b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS time_point 13560b57cec5SDimitry Andric{ 13570b57cec5SDimitry Andric static_assert(__is_duration<_Duration>::value, 13580b57cec5SDimitry Andric "Second template parameter of time_point must be a std::chrono::duration"); 13590b57cec5SDimitry Andricpublic: 13600b57cec5SDimitry Andric typedef _Clock clock; 13610b57cec5SDimitry Andric typedef _Duration duration; 13620b57cec5SDimitry Andric typedef typename duration::rep rep; 13630b57cec5SDimitry Andric typedef typename duration::period period; 13640b57cec5SDimitry Andricprivate: 13650b57cec5SDimitry Andric duration __d_; 13660b57cec5SDimitry Andric 13670b57cec5SDimitry Andricpublic: 13680b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {} 13690b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {} 13700b57cec5SDimitry Andric 13710b57cec5SDimitry Andric // conversions 13720b57cec5SDimitry Andric template <class _Duration2> 13730b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 13740b57cec5SDimitry Andric time_point(const time_point<clock, _Duration2>& t, 13750b57cec5SDimitry Andric typename enable_if 13760b57cec5SDimitry Andric < 13770b57cec5SDimitry Andric is_convertible<_Duration2, duration>::value 13780b57cec5SDimitry Andric >::type* = 0) 13790b57cec5SDimitry Andric : __d_(t.time_since_epoch()) {} 13800b57cec5SDimitry Andric 13810b57cec5SDimitry Andric // observer 13820b57cec5SDimitry Andric 13830b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;} 13840b57cec5SDimitry Andric 13850b57cec5SDimitry Andric // arithmetic 13860b57cec5SDimitry Andric 13870b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;} 13880b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;} 13890b57cec5SDimitry Andric 13900b57cec5SDimitry Andric // special values 13910b57cec5SDimitry Andric 13920b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());} 13930b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());} 13940b57cec5SDimitry Andric}; 13950b57cec5SDimitry Andric 13960b57cec5SDimitry Andric} // chrono 13970b57cec5SDimitry Andric 13980b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Duration2> 13990b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>, 14000b57cec5SDimitry Andric chrono::time_point<_Clock, _Duration2> > 14010b57cec5SDimitry Andric{ 14020b57cec5SDimitry Andric typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type; 14030b57cec5SDimitry Andric}; 14040b57cec5SDimitry Andric 14050b57cec5SDimitry Andricnamespace chrono { 14060b57cec5SDimitry Andric 14070b57cec5SDimitry Andrictemplate <class _ToDuration, class _Clock, class _Duration> 14080b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 14090b57cec5SDimitry Andrictime_point<_Clock, _ToDuration> 14100b57cec5SDimitry Andrictime_point_cast(const time_point<_Clock, _Duration>& __t) 14110b57cec5SDimitry Andric{ 14120b57cec5SDimitry Andric return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); 14130b57cec5SDimitry Andric} 14140b57cec5SDimitry Andric 14150b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 14160b57cec5SDimitry Andrictemplate <class _ToDuration, class _Clock, class _Duration> 14170b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 14180b57cec5SDimitry Andrictypename enable_if 14190b57cec5SDimitry Andric< 14200b57cec5SDimitry Andric __is_duration<_ToDuration>::value, 14210b57cec5SDimitry Andric time_point<_Clock, _ToDuration> 14220b57cec5SDimitry Andric>::type 14230b57cec5SDimitry Andricfloor(const time_point<_Clock, _Duration>& __t) 14240b57cec5SDimitry Andric{ 14250b57cec5SDimitry Andric return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; 14260b57cec5SDimitry Andric} 14270b57cec5SDimitry Andric 14280b57cec5SDimitry Andrictemplate <class _ToDuration, class _Clock, class _Duration> 14290b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 14300b57cec5SDimitry Andrictypename enable_if 14310b57cec5SDimitry Andric< 14320b57cec5SDimitry Andric __is_duration<_ToDuration>::value, 14330b57cec5SDimitry Andric time_point<_Clock, _ToDuration> 14340b57cec5SDimitry Andric>::type 14350b57cec5SDimitry Andricceil(const time_point<_Clock, _Duration>& __t) 14360b57cec5SDimitry Andric{ 14370b57cec5SDimitry Andric return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; 14380b57cec5SDimitry Andric} 14390b57cec5SDimitry Andric 14400b57cec5SDimitry Andrictemplate <class _ToDuration, class _Clock, class _Duration> 14410b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 14420b57cec5SDimitry Andrictypename enable_if 14430b57cec5SDimitry Andric< 14440b57cec5SDimitry Andric __is_duration<_ToDuration>::value, 14450b57cec5SDimitry Andric time_point<_Clock, _ToDuration> 14460b57cec5SDimitry Andric>::type 14470b57cec5SDimitry Andricround(const time_point<_Clock, _Duration>& __t) 14480b57cec5SDimitry Andric{ 14490b57cec5SDimitry Andric return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; 14500b57cec5SDimitry Andric} 14510b57cec5SDimitry Andric 14520b57cec5SDimitry Andrictemplate <class _Rep, class _Period> 14530b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 14540b57cec5SDimitry Andrictypename enable_if 14550b57cec5SDimitry Andric< 14560b57cec5SDimitry Andric numeric_limits<_Rep>::is_signed, 14570b57cec5SDimitry Andric duration<_Rep, _Period> 14580b57cec5SDimitry Andric>::type 14590b57cec5SDimitry Andricabs(duration<_Rep, _Period> __d) 14600b57cec5SDimitry Andric{ 1461*e40139ffSDimitry Andric return __d >= __d.zero() ? +__d : -__d; 14620b57cec5SDimitry Andric} 14630b57cec5SDimitry Andric#endif 14640b57cec5SDimitry Andric 14650b57cec5SDimitry Andric// time_point == 14660b57cec5SDimitry Andric 14670b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Duration2> 14680b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 14690b57cec5SDimitry Andricbool 14700b57cec5SDimitry Andricoperator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 14710b57cec5SDimitry Andric{ 14720b57cec5SDimitry Andric return __lhs.time_since_epoch() == __rhs.time_since_epoch(); 14730b57cec5SDimitry Andric} 14740b57cec5SDimitry Andric 14750b57cec5SDimitry Andric// time_point != 14760b57cec5SDimitry Andric 14770b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Duration2> 14780b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 14790b57cec5SDimitry Andricbool 14800b57cec5SDimitry Andricoperator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 14810b57cec5SDimitry Andric{ 14820b57cec5SDimitry Andric return !(__lhs == __rhs); 14830b57cec5SDimitry Andric} 14840b57cec5SDimitry Andric 14850b57cec5SDimitry Andric// time_point < 14860b57cec5SDimitry Andric 14870b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Duration2> 14880b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 14890b57cec5SDimitry Andricbool 14900b57cec5SDimitry Andricoperator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 14910b57cec5SDimitry Andric{ 14920b57cec5SDimitry Andric return __lhs.time_since_epoch() < __rhs.time_since_epoch(); 14930b57cec5SDimitry Andric} 14940b57cec5SDimitry Andric 14950b57cec5SDimitry Andric// time_point > 14960b57cec5SDimitry Andric 14970b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Duration2> 14980b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 14990b57cec5SDimitry Andricbool 15000b57cec5SDimitry Andricoperator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 15010b57cec5SDimitry Andric{ 15020b57cec5SDimitry Andric return __rhs < __lhs; 15030b57cec5SDimitry Andric} 15040b57cec5SDimitry Andric 15050b57cec5SDimitry Andric// time_point <= 15060b57cec5SDimitry Andric 15070b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Duration2> 15080b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 15090b57cec5SDimitry Andricbool 15100b57cec5SDimitry Andricoperator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 15110b57cec5SDimitry Andric{ 15120b57cec5SDimitry Andric return !(__rhs < __lhs); 15130b57cec5SDimitry Andric} 15140b57cec5SDimitry Andric 15150b57cec5SDimitry Andric// time_point >= 15160b57cec5SDimitry Andric 15170b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Duration2> 15180b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 15190b57cec5SDimitry Andricbool 15200b57cec5SDimitry Andricoperator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 15210b57cec5SDimitry Andric{ 15220b57cec5SDimitry Andric return !(__lhs < __rhs); 15230b57cec5SDimitry Andric} 15240b57cec5SDimitry Andric 15250b57cec5SDimitry Andric// time_point operator+(time_point x, duration y); 15260b57cec5SDimitry Andric 15270b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Rep2, class _Period2> 15280b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 15290b57cec5SDimitry Andrictime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> 15300b57cec5SDimitry Andricoperator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 15310b57cec5SDimitry Andric{ 15320b57cec5SDimitry Andric typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr; 15330b57cec5SDimitry Andric return _Tr (__lhs.time_since_epoch() + __rhs); 15340b57cec5SDimitry Andric} 15350b57cec5SDimitry Andric 15360b57cec5SDimitry Andric// time_point operator+(duration x, time_point y); 15370b57cec5SDimitry Andric 15380b57cec5SDimitry Andrictemplate <class _Rep1, class _Period1, class _Clock, class _Duration2> 15390b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 15400b57cec5SDimitry Andrictime_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type> 15410b57cec5SDimitry Andricoperator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 15420b57cec5SDimitry Andric{ 15430b57cec5SDimitry Andric return __rhs + __lhs; 15440b57cec5SDimitry Andric} 15450b57cec5SDimitry Andric 15460b57cec5SDimitry Andric// time_point operator-(time_point x, duration y); 15470b57cec5SDimitry Andric 15480b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Rep2, class _Period2> 15490b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 15500b57cec5SDimitry Andrictime_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> 15510b57cec5SDimitry Andricoperator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs) 15520b57cec5SDimitry Andric{ 15530b57cec5SDimitry Andric typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret; 15540b57cec5SDimitry Andric return _Ret(__lhs.time_since_epoch() -__rhs); 15550b57cec5SDimitry Andric} 15560b57cec5SDimitry Andric 15570b57cec5SDimitry Andric// duration operator-(time_point x, time_point y); 15580b57cec5SDimitry Andric 15590b57cec5SDimitry Andrictemplate <class _Clock, class _Duration1, class _Duration2> 15600b57cec5SDimitry Andricinline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 15610b57cec5SDimitry Andrictypename common_type<_Duration1, _Duration2>::type 15620b57cec5SDimitry Andricoperator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs) 15630b57cec5SDimitry Andric{ 15640b57cec5SDimitry Andric return __lhs.time_since_epoch() - __rhs.time_since_epoch(); 15650b57cec5SDimitry Andric} 15660b57cec5SDimitry Andric 15670b57cec5SDimitry Andric////////////////////////////////////////////////////////// 15680b57cec5SDimitry Andric/////////////////////// clocks /////////////////////////// 15690b57cec5SDimitry Andric////////////////////////////////////////////////////////// 15700b57cec5SDimitry Andric 15710b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS system_clock 15720b57cec5SDimitry Andric{ 15730b57cec5SDimitry Andricpublic: 15740b57cec5SDimitry Andric typedef microseconds duration; 15750b57cec5SDimitry Andric typedef duration::rep rep; 15760b57cec5SDimitry Andric typedef duration::period period; 15770b57cec5SDimitry Andric typedef chrono::time_point<system_clock> time_point; 15780b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; 15790b57cec5SDimitry Andric 15800b57cec5SDimitry Andric static time_point now() _NOEXCEPT; 15810b57cec5SDimitry Andric static time_t to_time_t (const time_point& __t) _NOEXCEPT; 15820b57cec5SDimitry Andric static time_point from_time_t(time_t __t) _NOEXCEPT; 15830b57cec5SDimitry Andric}; 15840b57cec5SDimitry Andric 15850b57cec5SDimitry Andric#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK 15860b57cec5SDimitry Andricclass _LIBCPP_TYPE_VIS steady_clock 15870b57cec5SDimitry Andric{ 15880b57cec5SDimitry Andricpublic: 15890b57cec5SDimitry Andric typedef nanoseconds duration; 15900b57cec5SDimitry Andric typedef duration::rep rep; 15910b57cec5SDimitry Andric typedef duration::period period; 15920b57cec5SDimitry Andric typedef chrono::time_point<steady_clock, duration> time_point; 15930b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true; 15940b57cec5SDimitry Andric 15950b57cec5SDimitry Andric static time_point now() _NOEXCEPT; 15960b57cec5SDimitry Andric}; 15970b57cec5SDimitry Andric 15980b57cec5SDimitry Andrictypedef steady_clock high_resolution_clock; 15990b57cec5SDimitry Andric#else 16000b57cec5SDimitry Andrictypedef system_clock high_resolution_clock; 16010b57cec5SDimitry Andric#endif 16020b57cec5SDimitry Andric 16030b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 16040b57cec5SDimitry Andric// [time.clock.file], type file_clock 16050b57cec5SDimitry Andricusing file_clock = _VSTD_FS::_FilesystemClock; 16060b57cec5SDimitry Andric 16070b57cec5SDimitry Andrictemplate<class _Duration> 16080b57cec5SDimitry Andricusing file_time = time_point<file_clock, _Duration>; 16090b57cec5SDimitry Andric 16100b57cec5SDimitry Andric 16110b57cec5SDimitry Andrictemplate <class _Duration> 16120b57cec5SDimitry Andricusing sys_time = time_point<system_clock, _Duration>; 16130b57cec5SDimitry Andricusing sys_seconds = sys_time<seconds>; 16140b57cec5SDimitry Andricusing sys_days = sys_time<days>; 16150b57cec5SDimitry Andric 16160b57cec5SDimitry Andricstruct local_t {}; 16170b57cec5SDimitry Andrictemplate<class Duration> 16180b57cec5SDimitry Andricusing local_time = time_point<local_t, Duration>; 16190b57cec5SDimitry Andricusing local_seconds = local_time<seconds>; 16200b57cec5SDimitry Andricusing local_days = local_time<days>; 16210b57cec5SDimitry Andric 16220b57cec5SDimitry Andric 16230b57cec5SDimitry Andricstruct last_spec { explicit last_spec() = default; }; 16240b57cec5SDimitry Andric 16250b57cec5SDimitry Andricclass day { 16260b57cec5SDimitry Andricprivate: 16270b57cec5SDimitry Andric unsigned char __d; 16280b57cec5SDimitry Andricpublic: 16290b57cec5SDimitry Andric day() = default; 16300b57cec5SDimitry Andric explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {} 16310b57cec5SDimitry Andric inline constexpr day& operator++() noexcept { ++__d; return *this; } 16320b57cec5SDimitry Andric inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; } 16330b57cec5SDimitry Andric inline constexpr day& operator--() noexcept { --__d; return *this; } 16340b57cec5SDimitry Andric inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; } 16350b57cec5SDimitry Andric constexpr day& operator+=(const days& __dd) noexcept; 16360b57cec5SDimitry Andric constexpr day& operator-=(const days& __dd) noexcept; 16370b57cec5SDimitry Andric explicit inline constexpr operator unsigned() const noexcept { return __d; } 16380b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; } 16390b57cec5SDimitry Andric }; 16400b57cec5SDimitry Andric 16410b57cec5SDimitry Andric 16420b57cec5SDimitry Andricinline constexpr 16430b57cec5SDimitry Andricbool operator==(const day& __lhs, const day& __rhs) noexcept 16440b57cec5SDimitry Andric{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } 16450b57cec5SDimitry Andric 16460b57cec5SDimitry Andricinline constexpr 16470b57cec5SDimitry Andricbool operator!=(const day& __lhs, const day& __rhs) noexcept 16480b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 16490b57cec5SDimitry Andric 16500b57cec5SDimitry Andricinline constexpr 16510b57cec5SDimitry Andricbool operator< (const day& __lhs, const day& __rhs) noexcept 16520b57cec5SDimitry Andric{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } 16530b57cec5SDimitry Andric 16540b57cec5SDimitry Andricinline constexpr 16550b57cec5SDimitry Andricbool operator> (const day& __lhs, const day& __rhs) noexcept 16560b57cec5SDimitry Andric{ return __rhs < __lhs; } 16570b57cec5SDimitry Andric 16580b57cec5SDimitry Andricinline constexpr 16590b57cec5SDimitry Andricbool operator<=(const day& __lhs, const day& __rhs) noexcept 16600b57cec5SDimitry Andric{ return !(__rhs < __lhs);} 16610b57cec5SDimitry Andric 16620b57cec5SDimitry Andricinline constexpr 16630b57cec5SDimitry Andricbool operator>=(const day& __lhs, const day& __rhs) noexcept 16640b57cec5SDimitry Andric{ return !(__lhs < __rhs); } 16650b57cec5SDimitry Andric 16660b57cec5SDimitry Andricinline constexpr 16670b57cec5SDimitry Andricday operator+ (const day& __lhs, const days& __rhs) noexcept 16680b57cec5SDimitry Andric{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); } 16690b57cec5SDimitry Andric 16700b57cec5SDimitry Andricinline constexpr 16710b57cec5SDimitry Andricday operator+ (const days& __lhs, const day& __rhs) noexcept 16720b57cec5SDimitry Andric{ return __rhs + __lhs; } 16730b57cec5SDimitry Andric 16740b57cec5SDimitry Andricinline constexpr 16750b57cec5SDimitry Andricday operator- (const day& __lhs, const days& __rhs) noexcept 16760b57cec5SDimitry Andric{ return __lhs + -__rhs; } 16770b57cec5SDimitry Andric 16780b57cec5SDimitry Andricinline constexpr 16790b57cec5SDimitry Andricdays operator-(const day& __lhs, const day& __rhs) noexcept 16800b57cec5SDimitry Andric{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) - 16810b57cec5SDimitry Andric static_cast<int>(static_cast<unsigned>(__rhs))); } 16820b57cec5SDimitry Andric 16830b57cec5SDimitry Andricinline constexpr day& day::operator+=(const days& __dd) noexcept 16840b57cec5SDimitry Andric{ *this = *this + __dd; return *this; } 16850b57cec5SDimitry Andric 16860b57cec5SDimitry Andricinline constexpr day& day::operator-=(const days& __dd) noexcept 16870b57cec5SDimitry Andric{ *this = *this - __dd; return *this; } 16880b57cec5SDimitry Andric 16890b57cec5SDimitry Andric 16900b57cec5SDimitry Andricclass month { 16910b57cec5SDimitry Andricprivate: 16920b57cec5SDimitry Andric unsigned char __m; 16930b57cec5SDimitry Andricpublic: 16940b57cec5SDimitry Andric month() = default; 16950b57cec5SDimitry Andric explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {} 16960b57cec5SDimitry Andric inline constexpr month& operator++() noexcept { ++__m; return *this; } 16970b57cec5SDimitry Andric inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; } 16980b57cec5SDimitry Andric inline constexpr month& operator--() noexcept { --__m; return *this; } 16990b57cec5SDimitry Andric inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; } 17000b57cec5SDimitry Andric constexpr month& operator+=(const months& __m1) noexcept; 17010b57cec5SDimitry Andric constexpr month& operator-=(const months& __m1) noexcept; 17020b57cec5SDimitry Andric explicit inline constexpr operator unsigned() const noexcept { return __m; } 17030b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; } 17040b57cec5SDimitry Andric}; 17050b57cec5SDimitry Andric 17060b57cec5SDimitry Andric 17070b57cec5SDimitry Andricinline constexpr 17080b57cec5SDimitry Andricbool operator==(const month& __lhs, const month& __rhs) noexcept 17090b57cec5SDimitry Andric{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); } 17100b57cec5SDimitry Andric 17110b57cec5SDimitry Andricinline constexpr 17120b57cec5SDimitry Andricbool operator!=(const month& __lhs, const month& __rhs) noexcept 17130b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 17140b57cec5SDimitry Andric 17150b57cec5SDimitry Andricinline constexpr 17160b57cec5SDimitry Andricbool operator< (const month& __lhs, const month& __rhs) noexcept 17170b57cec5SDimitry Andric{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); } 17180b57cec5SDimitry Andric 17190b57cec5SDimitry Andricinline constexpr 17200b57cec5SDimitry Andricbool operator> (const month& __lhs, const month& __rhs) noexcept 17210b57cec5SDimitry Andric{ return __rhs < __lhs; } 17220b57cec5SDimitry Andric 17230b57cec5SDimitry Andricinline constexpr 17240b57cec5SDimitry Andricbool operator<=(const month& __lhs, const month& __rhs) noexcept 17250b57cec5SDimitry Andric{ return !(__rhs < __lhs); } 17260b57cec5SDimitry Andric 17270b57cec5SDimitry Andricinline constexpr 17280b57cec5SDimitry Andricbool operator>=(const month& __lhs, const month& __rhs) noexcept 17290b57cec5SDimitry Andric{ return !(__lhs < __rhs); } 17300b57cec5SDimitry Andric 17310b57cec5SDimitry Andricinline constexpr 17320b57cec5SDimitry Andricmonth operator+ (const month& __lhs, const months& __rhs) noexcept 17330b57cec5SDimitry Andric{ 17340b57cec5SDimitry Andric auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1); 17350b57cec5SDimitry Andric auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12; 17360b57cec5SDimitry Andric return month{static_cast<unsigned>(__mu - __yr * 12 + 1)}; 17370b57cec5SDimitry Andric} 17380b57cec5SDimitry Andric 17390b57cec5SDimitry Andricinline constexpr 17400b57cec5SDimitry Andricmonth operator+ (const months& __lhs, const month& __rhs) noexcept 17410b57cec5SDimitry Andric{ return __rhs + __lhs; } 17420b57cec5SDimitry Andric 17430b57cec5SDimitry Andricinline constexpr 17440b57cec5SDimitry Andricmonth operator- (const month& __lhs, const months& __rhs) noexcept 17450b57cec5SDimitry Andric{ return __lhs + -__rhs; } 17460b57cec5SDimitry Andric 17470b57cec5SDimitry Andricinline constexpr 17480b57cec5SDimitry Andricmonths operator-(const month& __lhs, const month& __rhs) noexcept 17490b57cec5SDimitry Andric{ 17500b57cec5SDimitry Andric auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs); 17510b57cec5SDimitry Andric return months(__dm <= 11 ? __dm : __dm + 12); 17520b57cec5SDimitry Andric} 17530b57cec5SDimitry Andric 17540b57cec5SDimitry Andricinline constexpr month& month::operator+=(const months& __dm) noexcept 17550b57cec5SDimitry Andric{ *this = *this + __dm; return *this; } 17560b57cec5SDimitry Andric 17570b57cec5SDimitry Andricinline constexpr month& month::operator-=(const months& __dm) noexcept 17580b57cec5SDimitry Andric{ *this = *this - __dm; return *this; } 17590b57cec5SDimitry Andric 17600b57cec5SDimitry Andric 17610b57cec5SDimitry Andricclass year { 17620b57cec5SDimitry Andricprivate: 17630b57cec5SDimitry Andric short __y; 17640b57cec5SDimitry Andricpublic: 17650b57cec5SDimitry Andric year() = default; 17660b57cec5SDimitry Andric explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {} 17670b57cec5SDimitry Andric 17680b57cec5SDimitry Andric inline constexpr year& operator++() noexcept { ++__y; return *this; } 17690b57cec5SDimitry Andric inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; } 17700b57cec5SDimitry Andric inline constexpr year& operator--() noexcept { --__y; return *this; } 17710b57cec5SDimitry Andric inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; } 17720b57cec5SDimitry Andric constexpr year& operator+=(const years& __dy) noexcept; 17730b57cec5SDimitry Andric constexpr year& operator-=(const years& __dy) noexcept; 17740b57cec5SDimitry Andric inline constexpr year operator+() const noexcept { return *this; } 17750b57cec5SDimitry Andric inline constexpr year operator-() const noexcept { return year{-__y}; } 17760b57cec5SDimitry Andric 17770b57cec5SDimitry Andric inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); } 17780b57cec5SDimitry Andric explicit inline constexpr operator int() const noexcept { return __y; } 17790b57cec5SDimitry Andric constexpr bool ok() const noexcept; 17800b57cec5SDimitry Andric static inline constexpr year min() noexcept { return year{-32767}; } 17810b57cec5SDimitry Andric static inline constexpr year max() noexcept { return year{ 32767}; } 17820b57cec5SDimitry Andric}; 17830b57cec5SDimitry Andric 17840b57cec5SDimitry Andric 17850b57cec5SDimitry Andricinline constexpr 17860b57cec5SDimitry Andricbool operator==(const year& __lhs, const year& __rhs) noexcept 17870b57cec5SDimitry Andric{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); } 17880b57cec5SDimitry Andric 17890b57cec5SDimitry Andricinline constexpr 17900b57cec5SDimitry Andricbool operator!=(const year& __lhs, const year& __rhs) noexcept 17910b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 17920b57cec5SDimitry Andric 17930b57cec5SDimitry Andricinline constexpr 17940b57cec5SDimitry Andricbool operator< (const year& __lhs, const year& __rhs) noexcept 17950b57cec5SDimitry Andric{ return static_cast<int>(__lhs) < static_cast<int>(__rhs); } 17960b57cec5SDimitry Andric 17970b57cec5SDimitry Andricinline constexpr 17980b57cec5SDimitry Andricbool operator> (const year& __lhs, const year& __rhs) noexcept 17990b57cec5SDimitry Andric{ return __rhs < __lhs; } 18000b57cec5SDimitry Andric 18010b57cec5SDimitry Andricinline constexpr 18020b57cec5SDimitry Andricbool operator<=(const year& __lhs, const year& __rhs) noexcept 18030b57cec5SDimitry Andric{ return !(__rhs < __lhs); } 18040b57cec5SDimitry Andric 18050b57cec5SDimitry Andricinline constexpr 18060b57cec5SDimitry Andricbool operator>=(const year& __lhs, const year& __rhs) noexcept 18070b57cec5SDimitry Andric{ return !(__lhs < __rhs); } 18080b57cec5SDimitry Andric 18090b57cec5SDimitry Andricinline constexpr 18100b57cec5SDimitry Andricyear operator+ (const year& __lhs, const years& __rhs) noexcept 18110b57cec5SDimitry Andric{ return year(static_cast<int>(__lhs) + __rhs.count()); } 18120b57cec5SDimitry Andric 18130b57cec5SDimitry Andricinline constexpr 18140b57cec5SDimitry Andricyear operator+ (const years& __lhs, const year& __rhs) noexcept 18150b57cec5SDimitry Andric{ return __rhs + __lhs; } 18160b57cec5SDimitry Andric 18170b57cec5SDimitry Andricinline constexpr 18180b57cec5SDimitry Andricyear operator- (const year& __lhs, const years& __rhs) noexcept 18190b57cec5SDimitry Andric{ return __lhs + -__rhs; } 18200b57cec5SDimitry Andric 18210b57cec5SDimitry Andricinline constexpr 18220b57cec5SDimitry Andricyears operator-(const year& __lhs, const year& __rhs) noexcept 18230b57cec5SDimitry Andric{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; } 18240b57cec5SDimitry Andric 18250b57cec5SDimitry Andric 18260b57cec5SDimitry Andricinline constexpr year& year::operator+=(const years& __dy) noexcept 18270b57cec5SDimitry Andric{ *this = *this + __dy; return *this; } 18280b57cec5SDimitry Andric 18290b57cec5SDimitry Andricinline constexpr year& year::operator-=(const years& __dy) noexcept 18300b57cec5SDimitry Andric{ *this = *this - __dy; return *this; } 18310b57cec5SDimitry Andric 18320b57cec5SDimitry Andricinline constexpr bool year::ok() const noexcept 18330b57cec5SDimitry Andric{ return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); } 18340b57cec5SDimitry Andric 18350b57cec5SDimitry Andricclass weekday_indexed; 18360b57cec5SDimitry Andricclass weekday_last; 18370b57cec5SDimitry Andric 18380b57cec5SDimitry Andricclass weekday { 18390b57cec5SDimitry Andricprivate: 18400b57cec5SDimitry Andric unsigned char __wd; 18410b57cec5SDimitry Andricpublic: 18420b57cec5SDimitry Andric weekday() = default; 1843*e40139ffSDimitry Andric inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {} 18440b57cec5SDimitry Andric inline constexpr weekday(const sys_days& __sysd) noexcept 18450b57cec5SDimitry Andric : __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {} 18460b57cec5SDimitry Andric inline explicit constexpr weekday(const local_days& __locd) noexcept 18470b57cec5SDimitry Andric : __wd(__weekday_from_days(__locd.time_since_epoch().count())) {} 18480b57cec5SDimitry Andric 18490b57cec5SDimitry Andric inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; } 18500b57cec5SDimitry Andric inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; } 18510b57cec5SDimitry Andric inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; } 18520b57cec5SDimitry Andric inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; } 18530b57cec5SDimitry Andric constexpr weekday& operator+=(const days& __dd) noexcept; 18540b57cec5SDimitry Andric constexpr weekday& operator-=(const days& __dd) noexcept; 1855*e40139ffSDimitry Andric inline constexpr unsigned c_encoding() const noexcept { return __wd; } 1856*e40139ffSDimitry Andric inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; } 18570b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __wd <= 6; } 18580b57cec5SDimitry Andric constexpr weekday_indexed operator[](unsigned __index) const noexcept; 18590b57cec5SDimitry Andric constexpr weekday_last operator[](last_spec) const noexcept; 18600b57cec5SDimitry Andric 18610b57cec5SDimitry Andric static constexpr unsigned char __weekday_from_days(int __days) noexcept; 18620b57cec5SDimitry Andric}; 18630b57cec5SDimitry Andric 18640b57cec5SDimitry Andric 18650b57cec5SDimitry Andric// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days 18660b57cec5SDimitry Andricinline constexpr 18670b57cec5SDimitry Andricunsigned char weekday::__weekday_from_days(int __days) noexcept 18680b57cec5SDimitry Andric{ 18690b57cec5SDimitry Andric return static_cast<unsigned char>( 18700b57cec5SDimitry Andric static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6) 18710b57cec5SDimitry Andric ); 18720b57cec5SDimitry Andric} 18730b57cec5SDimitry Andric 18740b57cec5SDimitry Andricinline constexpr 18750b57cec5SDimitry Andricbool operator==(const weekday& __lhs, const weekday& __rhs) noexcept 1876*e40139ffSDimitry Andric{ return __lhs.c_encoding() == __rhs.c_encoding(); } 18770b57cec5SDimitry Andric 18780b57cec5SDimitry Andricinline constexpr 18790b57cec5SDimitry Andricbool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept 18800b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 18810b57cec5SDimitry Andric 18820b57cec5SDimitry Andricinline constexpr 18830b57cec5SDimitry Andricbool operator< (const weekday& __lhs, const weekday& __rhs) noexcept 1884*e40139ffSDimitry Andric{ return __lhs.c_encoding() < __rhs.c_encoding(); } 18850b57cec5SDimitry Andric 18860b57cec5SDimitry Andricinline constexpr 18870b57cec5SDimitry Andricbool operator> (const weekday& __lhs, const weekday& __rhs) noexcept 18880b57cec5SDimitry Andric{ return __rhs < __lhs; } 18890b57cec5SDimitry Andric 18900b57cec5SDimitry Andricinline constexpr 18910b57cec5SDimitry Andricbool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept 18920b57cec5SDimitry Andric{ return !(__rhs < __lhs);} 18930b57cec5SDimitry Andric 18940b57cec5SDimitry Andricinline constexpr 18950b57cec5SDimitry Andricbool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept 18960b57cec5SDimitry Andric{ return !(__lhs < __rhs); } 18970b57cec5SDimitry Andric 18980b57cec5SDimitry Andricconstexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept 18990b57cec5SDimitry Andric{ 1900*e40139ffSDimitry Andric auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count(); 19010b57cec5SDimitry Andric auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7; 19020b57cec5SDimitry Andric return weekday{static_cast<unsigned>(__mu - __yr * 7)}; 19030b57cec5SDimitry Andric} 19040b57cec5SDimitry Andric 19050b57cec5SDimitry Andricconstexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept 19060b57cec5SDimitry Andric{ return __rhs + __lhs; } 19070b57cec5SDimitry Andric 19080b57cec5SDimitry Andricconstexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept 19090b57cec5SDimitry Andric{ return __lhs + -__rhs; } 19100b57cec5SDimitry Andric 19110b57cec5SDimitry Andricconstexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept 19120b57cec5SDimitry Andric{ 1913*e40139ffSDimitry Andric const int __wdu = __lhs.c_encoding() - __rhs.c_encoding(); 19140b57cec5SDimitry Andric const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7; 19150b57cec5SDimitry Andric return days{__wdu - __wk * 7}; 19160b57cec5SDimitry Andric} 19170b57cec5SDimitry Andric 19180b57cec5SDimitry Andricinline constexpr weekday& weekday::operator+=(const days& __dd) noexcept 19190b57cec5SDimitry Andric{ *this = *this + __dd; return *this; } 19200b57cec5SDimitry Andric 19210b57cec5SDimitry Andricinline constexpr weekday& weekday::operator-=(const days& __dd) noexcept 19220b57cec5SDimitry Andric{ *this = *this - __dd; return *this; } 19230b57cec5SDimitry Andric 19240b57cec5SDimitry Andric 19250b57cec5SDimitry Andricclass weekday_indexed { 19260b57cec5SDimitry Andricprivate: 19270b57cec5SDimitry Andric _VSTD::chrono::weekday __wd; 19280b57cec5SDimitry Andric unsigned char __idx; 19290b57cec5SDimitry Andricpublic: 19300b57cec5SDimitry Andric weekday_indexed() = default; 19310b57cec5SDimitry Andric inline constexpr weekday_indexed(const _VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept 19320b57cec5SDimitry Andric : __wd{__wdval}, __idx(__idxval) {} 19330b57cec5SDimitry Andric inline constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; } 19340b57cec5SDimitry Andric inline constexpr unsigned index() const noexcept { return __idx; } 19350b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; } 19360b57cec5SDimitry Andric}; 19370b57cec5SDimitry Andric 19380b57cec5SDimitry Andricinline constexpr 19390b57cec5SDimitry Andricbool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept 19400b57cec5SDimitry Andric{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); } 19410b57cec5SDimitry Andric 19420b57cec5SDimitry Andricinline constexpr 19430b57cec5SDimitry Andricbool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept 19440b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 19450b57cec5SDimitry Andric 19460b57cec5SDimitry Andric 19470b57cec5SDimitry Andricclass weekday_last { 19480b57cec5SDimitry Andricprivate: 19490b57cec5SDimitry Andric _VSTD::chrono::weekday __wd; 19500b57cec5SDimitry Andricpublic: 19510b57cec5SDimitry Andric explicit constexpr weekday_last(const _VSTD::chrono::weekday& __val) noexcept 19520b57cec5SDimitry Andric : __wd{__val} {} 19530b57cec5SDimitry Andric constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; } 19540b57cec5SDimitry Andric constexpr bool ok() const noexcept { return __wd.ok(); } 19550b57cec5SDimitry Andric}; 19560b57cec5SDimitry Andric 19570b57cec5SDimitry Andricinline constexpr 19580b57cec5SDimitry Andricbool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept 19590b57cec5SDimitry Andric{ return __lhs.weekday() == __rhs.weekday(); } 19600b57cec5SDimitry Andric 19610b57cec5SDimitry Andricinline constexpr 19620b57cec5SDimitry Andricbool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept 19630b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 19640b57cec5SDimitry Andric 19650b57cec5SDimitry Andricinline constexpr 19660b57cec5SDimitry Andricweekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; } 19670b57cec5SDimitry Andric 19680b57cec5SDimitry Andricinline constexpr 19690b57cec5SDimitry Andricweekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; } 19700b57cec5SDimitry Andric 19710b57cec5SDimitry Andric 19720b57cec5SDimitry Andricinline constexpr last_spec last{}; 19730b57cec5SDimitry Andricinline constexpr weekday Sunday{0}; 19740b57cec5SDimitry Andricinline constexpr weekday Monday{1}; 19750b57cec5SDimitry Andricinline constexpr weekday Tuesday{2}; 19760b57cec5SDimitry Andricinline constexpr weekday Wednesday{3}; 19770b57cec5SDimitry Andricinline constexpr weekday Thursday{4}; 19780b57cec5SDimitry Andricinline constexpr weekday Friday{5}; 19790b57cec5SDimitry Andricinline constexpr weekday Saturday{6}; 19800b57cec5SDimitry Andric 19810b57cec5SDimitry Andricinline constexpr month January{1}; 19820b57cec5SDimitry Andricinline constexpr month February{2}; 19830b57cec5SDimitry Andricinline constexpr month March{3}; 19840b57cec5SDimitry Andricinline constexpr month April{4}; 19850b57cec5SDimitry Andricinline constexpr month May{5}; 19860b57cec5SDimitry Andricinline constexpr month June{6}; 19870b57cec5SDimitry Andricinline constexpr month July{7}; 19880b57cec5SDimitry Andricinline constexpr month August{8}; 19890b57cec5SDimitry Andricinline constexpr month September{9}; 19900b57cec5SDimitry Andricinline constexpr month October{10}; 19910b57cec5SDimitry Andricinline constexpr month November{11}; 19920b57cec5SDimitry Andricinline constexpr month December{12}; 19930b57cec5SDimitry Andric 19940b57cec5SDimitry Andric 19950b57cec5SDimitry Andricclass month_day { 19960b57cec5SDimitry Andricprivate: 19970b57cec5SDimitry Andric chrono::month __m; 19980b57cec5SDimitry Andric chrono::day __d; 19990b57cec5SDimitry Andricpublic: 20000b57cec5SDimitry Andric month_day() = default; 20010b57cec5SDimitry Andric constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept 20020b57cec5SDimitry Andric : __m{__mval}, __d{__dval} {} 20030b57cec5SDimitry Andric inline constexpr chrono::month month() const noexcept { return __m; } 20040b57cec5SDimitry Andric inline constexpr chrono::day day() const noexcept { return __d; } 20050b57cec5SDimitry Andric constexpr bool ok() const noexcept; 20060b57cec5SDimitry Andric}; 20070b57cec5SDimitry Andric 20080b57cec5SDimitry Andricinline constexpr 20090b57cec5SDimitry Andricbool month_day::ok() const noexcept 20100b57cec5SDimitry Andric{ 20110b57cec5SDimitry Andric if (!__m.ok()) return false; 20120b57cec5SDimitry Andric const unsigned __dval = static_cast<unsigned>(__d); 20130b57cec5SDimitry Andric if (__dval < 1 || __dval > 31) return false; 20140b57cec5SDimitry Andric if (__dval <= 29) return true; 20150b57cec5SDimitry Andric// Now we've got either 30 or 31 20160b57cec5SDimitry Andric const unsigned __mval = static_cast<unsigned>(__m); 20170b57cec5SDimitry Andric if (__mval == 2) return false; 20180b57cec5SDimitry Andric if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11) 20190b57cec5SDimitry Andric return __dval == 30; 20200b57cec5SDimitry Andric return true; 20210b57cec5SDimitry Andric} 20220b57cec5SDimitry Andric 20230b57cec5SDimitry Andricinline constexpr 20240b57cec5SDimitry Andricbool operator==(const month_day& __lhs, const month_day& __rhs) noexcept 20250b57cec5SDimitry Andric{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } 20260b57cec5SDimitry Andric 20270b57cec5SDimitry Andricinline constexpr 20280b57cec5SDimitry Andricbool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept 20290b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 20300b57cec5SDimitry Andric 20310b57cec5SDimitry Andricinline constexpr 20320b57cec5SDimitry Andricmonth_day operator/(const month& __lhs, const day& __rhs) noexcept 20330b57cec5SDimitry Andric{ return month_day{__lhs, __rhs}; } 20340b57cec5SDimitry Andric 20350b57cec5SDimitry Andricconstexpr 20360b57cec5SDimitry Andricmonth_day operator/(const day& __lhs, const month& __rhs) noexcept 20370b57cec5SDimitry Andric{ return __rhs / __lhs; } 20380b57cec5SDimitry Andric 20390b57cec5SDimitry Andricinline constexpr 20400b57cec5SDimitry Andricmonth_day operator/(const month& __lhs, int __rhs) noexcept 20410b57cec5SDimitry Andric{ return __lhs / day(__rhs); } 20420b57cec5SDimitry Andric 20430b57cec5SDimitry Andricconstexpr 20440b57cec5SDimitry Andricmonth_day operator/(int __lhs, const day& __rhs) noexcept 20450b57cec5SDimitry Andric{ return month(__lhs) / __rhs; } 20460b57cec5SDimitry Andric 20470b57cec5SDimitry Andricconstexpr 20480b57cec5SDimitry Andricmonth_day operator/(const day& __lhs, int __rhs) noexcept 20490b57cec5SDimitry Andric{ return month(__rhs) / __lhs; } 20500b57cec5SDimitry Andric 20510b57cec5SDimitry Andric 20520b57cec5SDimitry Andricinline constexpr 20530b57cec5SDimitry Andricbool operator< (const month_day& __lhs, const month_day& __rhs) noexcept 20540b57cec5SDimitry Andric{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); } 20550b57cec5SDimitry Andric 20560b57cec5SDimitry Andricinline constexpr 20570b57cec5SDimitry Andricbool operator> (const month_day& __lhs, const month_day& __rhs) noexcept 20580b57cec5SDimitry Andric{ return __rhs < __lhs; } 20590b57cec5SDimitry Andric 20600b57cec5SDimitry Andricinline constexpr 20610b57cec5SDimitry Andricbool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept 20620b57cec5SDimitry Andric{ return !(__rhs < __lhs);} 20630b57cec5SDimitry Andric 20640b57cec5SDimitry Andricinline constexpr 20650b57cec5SDimitry Andricbool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept 20660b57cec5SDimitry Andric{ return !(__lhs < __rhs); } 20670b57cec5SDimitry Andric 20680b57cec5SDimitry Andric 20690b57cec5SDimitry Andric 20700b57cec5SDimitry Andricclass month_day_last { 20710b57cec5SDimitry Andricprivate: 20720b57cec5SDimitry Andric chrono::month __m; 20730b57cec5SDimitry Andricpublic: 20740b57cec5SDimitry Andric explicit constexpr month_day_last(const chrono::month& __val) noexcept 20750b57cec5SDimitry Andric : __m{__val} {} 20760b57cec5SDimitry Andric inline constexpr chrono::month month() const noexcept { return __m; } 20770b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __m.ok(); } 20780b57cec5SDimitry Andric}; 20790b57cec5SDimitry Andric 20800b57cec5SDimitry Andricinline constexpr 20810b57cec5SDimitry Andricbool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 20820b57cec5SDimitry Andric{ return __lhs.month() == __rhs.month(); } 20830b57cec5SDimitry Andric 20840b57cec5SDimitry Andricinline constexpr 20850b57cec5SDimitry Andricbool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 20860b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 20870b57cec5SDimitry Andric 20880b57cec5SDimitry Andricinline constexpr 20890b57cec5SDimitry Andricbool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept 20900b57cec5SDimitry Andric{ return __lhs.month() < __rhs.month(); } 20910b57cec5SDimitry Andric 20920b57cec5SDimitry Andricinline constexpr 20930b57cec5SDimitry Andricbool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept 20940b57cec5SDimitry Andric{ return __rhs < __lhs; } 20950b57cec5SDimitry Andric 20960b57cec5SDimitry Andricinline constexpr 20970b57cec5SDimitry Andricbool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 20980b57cec5SDimitry Andric{ return !(__rhs < __lhs);} 20990b57cec5SDimitry Andric 21000b57cec5SDimitry Andricinline constexpr 21010b57cec5SDimitry Andricbool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept 21020b57cec5SDimitry Andric{ return !(__lhs < __rhs); } 21030b57cec5SDimitry Andric 21040b57cec5SDimitry Andricinline constexpr 21050b57cec5SDimitry Andricmonth_day_last operator/(const month& __lhs, last_spec) noexcept 21060b57cec5SDimitry Andric{ return month_day_last{__lhs}; } 21070b57cec5SDimitry Andric 21080b57cec5SDimitry Andricinline constexpr 21090b57cec5SDimitry Andricmonth_day_last operator/(last_spec, const month& __rhs) noexcept 21100b57cec5SDimitry Andric{ return month_day_last{__rhs}; } 21110b57cec5SDimitry Andric 21120b57cec5SDimitry Andricinline constexpr 21130b57cec5SDimitry Andricmonth_day_last operator/(int __lhs, last_spec) noexcept 21140b57cec5SDimitry Andric{ return month_day_last{month(__lhs)}; } 21150b57cec5SDimitry Andric 21160b57cec5SDimitry Andricinline constexpr 21170b57cec5SDimitry Andricmonth_day_last operator/(last_spec, int __rhs) noexcept 21180b57cec5SDimitry Andric{ return month_day_last{month(__rhs)}; } 21190b57cec5SDimitry Andric 21200b57cec5SDimitry Andric 21210b57cec5SDimitry Andricclass month_weekday { 21220b57cec5SDimitry Andricprivate: 21230b57cec5SDimitry Andric chrono::month __m; 21240b57cec5SDimitry Andric chrono::weekday_indexed __wdi; 21250b57cec5SDimitry Andricpublic: 21260b57cec5SDimitry Andric month_weekday() = default; 21270b57cec5SDimitry Andric constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept 21280b57cec5SDimitry Andric : __m{__mval}, __wdi{__wdival} {} 21290b57cec5SDimitry Andric inline constexpr chrono::month month() const noexcept { return __m; } 21300b57cec5SDimitry Andric inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } 21310b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); } 21320b57cec5SDimitry Andric}; 21330b57cec5SDimitry Andric 21340b57cec5SDimitry Andricinline constexpr 21350b57cec5SDimitry Andricbool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept 21360b57cec5SDimitry Andric{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } 21370b57cec5SDimitry Andric 21380b57cec5SDimitry Andricinline constexpr 21390b57cec5SDimitry Andricbool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept 21400b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 21410b57cec5SDimitry Andric 21420b57cec5SDimitry Andricinline constexpr 21430b57cec5SDimitry Andricmonth_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept 21440b57cec5SDimitry Andric{ return month_weekday{__lhs, __rhs}; } 21450b57cec5SDimitry Andric 21460b57cec5SDimitry Andricinline constexpr 21470b57cec5SDimitry Andricmonth_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept 21480b57cec5SDimitry Andric{ return month_weekday{month(__lhs), __rhs}; } 21490b57cec5SDimitry Andric 21500b57cec5SDimitry Andricinline constexpr 21510b57cec5SDimitry Andricmonth_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept 21520b57cec5SDimitry Andric{ return month_weekday{__rhs, __lhs}; } 21530b57cec5SDimitry Andric 21540b57cec5SDimitry Andricinline constexpr 21550b57cec5SDimitry Andricmonth_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept 21560b57cec5SDimitry Andric{ return month_weekday{month(__rhs), __lhs}; } 21570b57cec5SDimitry Andric 21580b57cec5SDimitry Andric 21590b57cec5SDimitry Andricclass month_weekday_last { 21600b57cec5SDimitry Andric chrono::month __m; 21610b57cec5SDimitry Andric chrono::weekday_last __wdl; 21620b57cec5SDimitry Andric public: 21630b57cec5SDimitry Andric constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept 21640b57cec5SDimitry Andric : __m{__mval}, __wdl{__wdlval} {} 21650b57cec5SDimitry Andric inline constexpr chrono::month month() const noexcept { return __m; } 21660b57cec5SDimitry Andric inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } 21670b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); } 21680b57cec5SDimitry Andric}; 21690b57cec5SDimitry Andric 21700b57cec5SDimitry Andricinline constexpr 21710b57cec5SDimitry Andricbool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept 21720b57cec5SDimitry Andric{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } 21730b57cec5SDimitry Andric 21740b57cec5SDimitry Andricinline constexpr 21750b57cec5SDimitry Andricbool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept 21760b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 21770b57cec5SDimitry Andric 21780b57cec5SDimitry Andric 21790b57cec5SDimitry Andricinline constexpr 21800b57cec5SDimitry Andricmonth_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept 21810b57cec5SDimitry Andric{ return month_weekday_last{__lhs, __rhs}; } 21820b57cec5SDimitry Andric 21830b57cec5SDimitry Andricinline constexpr 21840b57cec5SDimitry Andricmonth_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept 21850b57cec5SDimitry Andric{ return month_weekday_last{month(__lhs), __rhs}; } 21860b57cec5SDimitry Andric 21870b57cec5SDimitry Andricinline constexpr 21880b57cec5SDimitry Andricmonth_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept 21890b57cec5SDimitry Andric{ return month_weekday_last{__rhs, __lhs}; } 21900b57cec5SDimitry Andric 21910b57cec5SDimitry Andricinline constexpr 21920b57cec5SDimitry Andricmonth_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept 21930b57cec5SDimitry Andric{ return month_weekday_last{month(__rhs), __lhs}; } 21940b57cec5SDimitry Andric 21950b57cec5SDimitry Andric 21960b57cec5SDimitry Andricclass year_month { 21970b57cec5SDimitry Andric chrono::year __y; 21980b57cec5SDimitry Andric chrono::month __m; 21990b57cec5SDimitry Andricpublic: 22000b57cec5SDimitry Andric year_month() = default; 22010b57cec5SDimitry Andric constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept 22020b57cec5SDimitry Andric : __y{__yval}, __m{__mval} {} 22030b57cec5SDimitry Andric inline constexpr chrono::year year() const noexcept { return __y; } 22040b57cec5SDimitry Andric inline constexpr chrono::month month() const noexcept { return __m; } 22050b57cec5SDimitry Andric inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; } 22060b57cec5SDimitry Andric inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; } 22070b57cec5SDimitry Andric inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; } 22080b57cec5SDimitry Andric inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; } 22090b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); } 22100b57cec5SDimitry Andric}; 22110b57cec5SDimitry Andric 22120b57cec5SDimitry Andricinline constexpr 22130b57cec5SDimitry Andricyear_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; } 22140b57cec5SDimitry Andric 22150b57cec5SDimitry Andricinline constexpr 22160b57cec5SDimitry Andricyear_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; } 22170b57cec5SDimitry Andric 22180b57cec5SDimitry Andricinline constexpr 22190b57cec5SDimitry Andricbool operator==(const year_month& __lhs, const year_month& __rhs) noexcept 22200b57cec5SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); } 22210b57cec5SDimitry Andric 22220b57cec5SDimitry Andricinline constexpr 22230b57cec5SDimitry Andricbool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept 22240b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 22250b57cec5SDimitry Andric 22260b57cec5SDimitry Andricinline constexpr 22270b57cec5SDimitry Andricbool operator< (const year_month& __lhs, const year_month& __rhs) noexcept 22280b57cec5SDimitry Andric{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); } 22290b57cec5SDimitry Andric 22300b57cec5SDimitry Andricinline constexpr 22310b57cec5SDimitry Andricbool operator> (const year_month& __lhs, const year_month& __rhs) noexcept 22320b57cec5SDimitry Andric{ return __rhs < __lhs; } 22330b57cec5SDimitry Andric 22340b57cec5SDimitry Andricinline constexpr 22350b57cec5SDimitry Andricbool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept 22360b57cec5SDimitry Andric{ return !(__rhs < __lhs);} 22370b57cec5SDimitry Andric 22380b57cec5SDimitry Andricinline constexpr 22390b57cec5SDimitry Andricbool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept 22400b57cec5SDimitry Andric{ return !(__lhs < __rhs); } 22410b57cec5SDimitry Andric 22420b57cec5SDimitry Andricconstexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept 22430b57cec5SDimitry Andric{ 22440b57cec5SDimitry Andric int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count(); 22450b57cec5SDimitry Andric const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12; 22460b57cec5SDimitry Andric __dmi = __dmi - __dy * 12 + 1; 22470b57cec5SDimitry Andric return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi)); 22480b57cec5SDimitry Andric} 22490b57cec5SDimitry Andric 22500b57cec5SDimitry Andricconstexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept 22510b57cec5SDimitry Andric{ return __rhs + __lhs; } 22520b57cec5SDimitry Andric 22530b57cec5SDimitry Andricconstexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept 22540b57cec5SDimitry Andric{ return (__lhs.year() + __rhs) / __lhs.month(); } 22550b57cec5SDimitry Andric 22560b57cec5SDimitry Andricconstexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept 22570b57cec5SDimitry Andric{ return __rhs + __lhs; } 22580b57cec5SDimitry Andric 22590b57cec5SDimitry Andricconstexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept 22600b57cec5SDimitry Andric{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); } 22610b57cec5SDimitry Andric 22620b57cec5SDimitry Andricconstexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept 22630b57cec5SDimitry Andric{ return __lhs + -__rhs; } 22640b57cec5SDimitry Andric 22650b57cec5SDimitry Andricconstexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept 22660b57cec5SDimitry Andric{ return __lhs + -__rhs; } 22670b57cec5SDimitry Andric 22680b57cec5SDimitry Andricclass year_month_day_last; 22690b57cec5SDimitry Andric 22700b57cec5SDimitry Andricclass year_month_day { 22710b57cec5SDimitry Andricprivate: 22720b57cec5SDimitry Andric chrono::year __y; 22730b57cec5SDimitry Andric chrono::month __m; 22740b57cec5SDimitry Andric chrono::day __d; 22750b57cec5SDimitry Andricpublic: 22760b57cec5SDimitry Andric year_month_day() = default; 22770b57cec5SDimitry Andric inline constexpr year_month_day( 22780b57cec5SDimitry Andric const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept 22790b57cec5SDimitry Andric : __y{__yval}, __m{__mval}, __d{__dval} {} 22800b57cec5SDimitry Andric constexpr year_month_day(const year_month_day_last& __ymdl) noexcept; 22810b57cec5SDimitry Andric inline constexpr year_month_day(const sys_days& __sysd) noexcept 22820b57cec5SDimitry Andric : year_month_day(__from_days(__sysd.time_since_epoch())) {} 22830b57cec5SDimitry Andric inline explicit constexpr year_month_day(const local_days& __locd) noexcept 22840b57cec5SDimitry Andric : year_month_day(__from_days(__locd.time_since_epoch())) {} 22850b57cec5SDimitry Andric 22860b57cec5SDimitry Andric constexpr year_month_day& operator+=(const months& __dm) noexcept; 22870b57cec5SDimitry Andric constexpr year_month_day& operator-=(const months& __dm) noexcept; 22880b57cec5SDimitry Andric constexpr year_month_day& operator+=(const years& __dy) noexcept; 22890b57cec5SDimitry Andric constexpr year_month_day& operator-=(const years& __dy) noexcept; 22900b57cec5SDimitry Andric 22910b57cec5SDimitry Andric inline constexpr chrono::year year() const noexcept { return __y; } 22920b57cec5SDimitry Andric inline constexpr chrono::month month() const noexcept { return __m; } 22930b57cec5SDimitry Andric inline constexpr chrono::day day() const noexcept { return __d; } 22940b57cec5SDimitry Andric inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } 22950b57cec5SDimitry Andric inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } 22960b57cec5SDimitry Andric 22970b57cec5SDimitry Andric constexpr bool ok() const noexcept; 22980b57cec5SDimitry Andric 22990b57cec5SDimitry Andric static constexpr year_month_day __from_days(days __d) noexcept; 23000b57cec5SDimitry Andric constexpr days __to_days() const noexcept; 23010b57cec5SDimitry Andric}; 23020b57cec5SDimitry Andric 23030b57cec5SDimitry Andric 23040b57cec5SDimitry Andric// https://howardhinnant.github.io/date_algorithms.html#civil_from_days 23050b57cec5SDimitry Andricinline constexpr 23060b57cec5SDimitry Andricyear_month_day 23070b57cec5SDimitry Andricyear_month_day::__from_days(days __d) noexcept 23080b57cec5SDimitry Andric{ 23090b57cec5SDimitry Andric static_assert(std::numeric_limits<unsigned>::digits >= 18, ""); 23100b57cec5SDimitry Andric static_assert(std::numeric_limits<int>::digits >= 20 , ""); 23110b57cec5SDimitry Andric const int __z = __d.count() + 719468; 23120b57cec5SDimitry Andric const int __era = (__z >= 0 ? __z : __z - 146096) / 146097; 23130b57cec5SDimitry Andric const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096] 23140b57cec5SDimitry Andric const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399] 23150b57cec5SDimitry Andric const int __yr = static_cast<int>(__yoe) + __era * 400; 23160b57cec5SDimitry Andric const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365] 23170b57cec5SDimitry Andric const unsigned __mp = (5 * __doy + 2)/153; // [0, 11] 23180b57cec5SDimitry Andric const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31] 23190b57cec5SDimitry Andric const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12] 23200b57cec5SDimitry Andric return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}}; 23210b57cec5SDimitry Andric} 23220b57cec5SDimitry Andric 23230b57cec5SDimitry Andric// https://howardhinnant.github.io/date_algorithms.html#days_from_civil 23240b57cec5SDimitry Andricinline constexpr days year_month_day::__to_days() const noexcept 23250b57cec5SDimitry Andric{ 23260b57cec5SDimitry Andric static_assert(std::numeric_limits<unsigned>::digits >= 18, ""); 23270b57cec5SDimitry Andric static_assert(std::numeric_limits<int>::digits >= 20 , ""); 23280b57cec5SDimitry Andric 23290b57cec5SDimitry Andric const int __yr = static_cast<int>(__y) - (__m <= February); 23300b57cec5SDimitry Andric const unsigned __mth = static_cast<unsigned>(__m); 23310b57cec5SDimitry Andric const unsigned __dy = static_cast<unsigned>(__d); 23320b57cec5SDimitry Andric 23330b57cec5SDimitry Andric const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400; 23340b57cec5SDimitry Andric const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399] 23350b57cec5SDimitry Andric const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365] 23360b57cec5SDimitry Andric const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096] 23370b57cec5SDimitry Andric return days{__era * 146097 + static_cast<int>(__doe) - 719468}; 23380b57cec5SDimitry Andric} 23390b57cec5SDimitry Andric 23400b57cec5SDimitry Andricinline constexpr 23410b57cec5SDimitry Andricbool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept 23420b57cec5SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); } 23430b57cec5SDimitry Andric 23440b57cec5SDimitry Andricinline constexpr 23450b57cec5SDimitry Andricbool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept 23460b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 23470b57cec5SDimitry Andric 23480b57cec5SDimitry Andricinline constexpr 23490b57cec5SDimitry Andricbool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept 23500b57cec5SDimitry Andric{ 23510b57cec5SDimitry Andric if (__lhs.year() < __rhs.year()) return true; 23520b57cec5SDimitry Andric if (__lhs.year() > __rhs.year()) return false; 23530b57cec5SDimitry Andric if (__lhs.month() < __rhs.month()) return true; 23540b57cec5SDimitry Andric if (__lhs.month() > __rhs.month()) return false; 23550b57cec5SDimitry Andric return __lhs.day() < __rhs.day(); 23560b57cec5SDimitry Andric} 23570b57cec5SDimitry Andric 23580b57cec5SDimitry Andricinline constexpr 23590b57cec5SDimitry Andricbool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept 23600b57cec5SDimitry Andric{ return __rhs < __lhs; } 23610b57cec5SDimitry Andric 23620b57cec5SDimitry Andricinline constexpr 23630b57cec5SDimitry Andricbool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept 23640b57cec5SDimitry Andric{ return !(__rhs < __lhs);} 23650b57cec5SDimitry Andric 23660b57cec5SDimitry Andricinline constexpr 23670b57cec5SDimitry Andricbool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept 23680b57cec5SDimitry Andric{ return !(__lhs < __rhs); } 23690b57cec5SDimitry Andric 23700b57cec5SDimitry Andricinline constexpr 23710b57cec5SDimitry Andricyear_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept 23720b57cec5SDimitry Andric{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; } 23730b57cec5SDimitry Andric 23740b57cec5SDimitry Andricinline constexpr 23750b57cec5SDimitry Andricyear_month_day operator/(const year_month& __lhs, int __rhs) noexcept 23760b57cec5SDimitry Andric{ return __lhs / day(__rhs); } 23770b57cec5SDimitry Andric 23780b57cec5SDimitry Andricinline constexpr 23790b57cec5SDimitry Andricyear_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept 23800b57cec5SDimitry Andric{ return __lhs / __rhs.month() / __rhs.day(); } 23810b57cec5SDimitry Andric 23820b57cec5SDimitry Andricinline constexpr 23830b57cec5SDimitry Andricyear_month_day operator/(int __lhs, const month_day& __rhs) noexcept 23840b57cec5SDimitry Andric{ return year(__lhs) / __rhs; } 23850b57cec5SDimitry Andric 23860b57cec5SDimitry Andricinline constexpr 23870b57cec5SDimitry Andricyear_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept 23880b57cec5SDimitry Andric{ return __rhs / __lhs; } 23890b57cec5SDimitry Andric 23900b57cec5SDimitry Andricinline constexpr 23910b57cec5SDimitry Andricyear_month_day operator/(const month_day& __lhs, int __rhs) noexcept 23920b57cec5SDimitry Andric{ return year(__rhs) / __lhs; } 23930b57cec5SDimitry Andric 23940b57cec5SDimitry Andric 23950b57cec5SDimitry Andricinline constexpr 23960b57cec5SDimitry Andricyear_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept 23970b57cec5SDimitry Andric{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); } 23980b57cec5SDimitry Andric 23990b57cec5SDimitry Andricinline constexpr 24000b57cec5SDimitry Andricyear_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept 24010b57cec5SDimitry Andric{ return __rhs + __lhs; } 24020b57cec5SDimitry Andric 24030b57cec5SDimitry Andricinline constexpr 24040b57cec5SDimitry Andricyear_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept 24050b57cec5SDimitry Andric{ return __lhs + -__rhs; } 24060b57cec5SDimitry Andric 24070b57cec5SDimitry Andricinline constexpr 24080b57cec5SDimitry Andricyear_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept 24090b57cec5SDimitry Andric{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); } 24100b57cec5SDimitry Andric 24110b57cec5SDimitry Andricinline constexpr 24120b57cec5SDimitry Andricyear_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept 24130b57cec5SDimitry Andric{ return __rhs + __lhs; } 24140b57cec5SDimitry Andric 24150b57cec5SDimitry Andricinline constexpr 24160b57cec5SDimitry Andricyear_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept 24170b57cec5SDimitry Andric{ return __lhs + -__rhs; } 24180b57cec5SDimitry Andric 24190b57cec5SDimitry Andricinline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } 24200b57cec5SDimitry Andricinline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } 24210b57cec5SDimitry Andricinline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } 24220b57cec5SDimitry Andricinline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } 24230b57cec5SDimitry Andric 24240b57cec5SDimitry Andricclass year_month_day_last { 24250b57cec5SDimitry Andricprivate: 24260b57cec5SDimitry Andric chrono::year __y; 24270b57cec5SDimitry Andric chrono::month_day_last __mdl; 24280b57cec5SDimitry Andricpublic: 24290b57cec5SDimitry Andric constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept 24300b57cec5SDimitry Andric : __y{__yval}, __mdl{__mdlval} {} 24310b57cec5SDimitry Andric 24320b57cec5SDimitry Andric constexpr year_month_day_last& operator+=(const months& __m) noexcept; 24330b57cec5SDimitry Andric constexpr year_month_day_last& operator-=(const months& __m) noexcept; 24340b57cec5SDimitry Andric constexpr year_month_day_last& operator+=(const years& __y) noexcept; 24350b57cec5SDimitry Andric constexpr year_month_day_last& operator-=(const years& __y) noexcept; 24360b57cec5SDimitry Andric 24370b57cec5SDimitry Andric inline constexpr chrono::year year() const noexcept { return __y; } 24380b57cec5SDimitry Andric inline constexpr chrono::month month() const noexcept { return __mdl.month(); } 24390b57cec5SDimitry Andric inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; } 24400b57cec5SDimitry Andric constexpr chrono::day day() const noexcept; 24410b57cec5SDimitry Andric inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; } 24420b57cec5SDimitry Andric inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; } 24430b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); } 24440b57cec5SDimitry Andric}; 24450b57cec5SDimitry Andric 24460b57cec5SDimitry Andricinline constexpr 24470b57cec5SDimitry Andricchrono::day year_month_day_last::day() const noexcept 24480b57cec5SDimitry Andric{ 24490b57cec5SDimitry Andric constexpr chrono::day __d[] = 24500b57cec5SDimitry Andric { 24510b57cec5SDimitry Andric chrono::day(31), chrono::day(28), chrono::day(31), 24520b57cec5SDimitry Andric chrono::day(30), chrono::day(31), chrono::day(30), 24530b57cec5SDimitry Andric chrono::day(31), chrono::day(31), chrono::day(30), 24540b57cec5SDimitry Andric chrono::day(31), chrono::day(30), chrono::day(31) 24550b57cec5SDimitry Andric }; 24560b57cec5SDimitry Andric return month() != February || !__y.is_leap() ? 24570b57cec5SDimitry Andric __d[static_cast<unsigned>(month()) - 1] : chrono::day{29}; 24580b57cec5SDimitry Andric} 24590b57cec5SDimitry Andric 24600b57cec5SDimitry Andricinline constexpr 24610b57cec5SDimitry Andricbool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 24620b57cec5SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); } 24630b57cec5SDimitry Andric 24640b57cec5SDimitry Andricinline constexpr 24650b57cec5SDimitry Andricbool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 24660b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 24670b57cec5SDimitry Andric 24680b57cec5SDimitry Andricinline constexpr 24690b57cec5SDimitry Andricbool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 24700b57cec5SDimitry Andric{ 24710b57cec5SDimitry Andric if (__lhs.year() < __rhs.year()) return true; 24720b57cec5SDimitry Andric if (__lhs.year() > __rhs.year()) return false; 24730b57cec5SDimitry Andric return __lhs.month_day_last() < __rhs.month_day_last(); 24740b57cec5SDimitry Andric} 24750b57cec5SDimitry Andric 24760b57cec5SDimitry Andricinline constexpr 24770b57cec5SDimitry Andricbool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 24780b57cec5SDimitry Andric{ return __rhs < __lhs; } 24790b57cec5SDimitry Andric 24800b57cec5SDimitry Andricinline constexpr 24810b57cec5SDimitry Andricbool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 24820b57cec5SDimitry Andric{ return !(__rhs < __lhs);} 24830b57cec5SDimitry Andric 24840b57cec5SDimitry Andricinline constexpr 24850b57cec5SDimitry Andricbool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept 24860b57cec5SDimitry Andric{ return !(__lhs < __rhs); } 24870b57cec5SDimitry Andric 24880b57cec5SDimitry Andricinline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept 24890b57cec5SDimitry Andric{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; } 24900b57cec5SDimitry Andric 24910b57cec5SDimitry Andricinline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept 24920b57cec5SDimitry Andric{ return year_month_day_last{__lhs, __rhs}; } 24930b57cec5SDimitry Andric 24940b57cec5SDimitry Andricinline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept 24950b57cec5SDimitry Andric{ return year_month_day_last{year{__lhs}, __rhs}; } 24960b57cec5SDimitry Andric 24970b57cec5SDimitry Andricinline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept 24980b57cec5SDimitry Andric{ return __rhs / __lhs; } 24990b57cec5SDimitry Andric 25000b57cec5SDimitry Andricinline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept 25010b57cec5SDimitry Andric{ return year{__rhs} / __lhs; } 25020b57cec5SDimitry Andric 25030b57cec5SDimitry Andric 25040b57cec5SDimitry Andricinline constexpr 25050b57cec5SDimitry Andricyear_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept 25060b57cec5SDimitry Andric{ return (__lhs.year() / __lhs.month() + __rhs) / last; } 25070b57cec5SDimitry Andric 25080b57cec5SDimitry Andricinline constexpr 25090b57cec5SDimitry Andricyear_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept 25100b57cec5SDimitry Andric{ return __rhs + __lhs; } 25110b57cec5SDimitry Andric 25120b57cec5SDimitry Andricinline constexpr 25130b57cec5SDimitry Andricyear_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept 25140b57cec5SDimitry Andric{ return __lhs + (-__rhs); } 25150b57cec5SDimitry Andric 25160b57cec5SDimitry Andricinline constexpr 25170b57cec5SDimitry Andricyear_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept 25180b57cec5SDimitry Andric{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; } 25190b57cec5SDimitry Andric 25200b57cec5SDimitry Andricinline constexpr 25210b57cec5SDimitry Andricyear_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept 25220b57cec5SDimitry Andric{ return __rhs + __lhs; } 25230b57cec5SDimitry Andric 25240b57cec5SDimitry Andricinline constexpr 25250b57cec5SDimitry Andricyear_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept 25260b57cec5SDimitry Andric{ return __lhs + (-__rhs); } 25270b57cec5SDimitry Andric 25280b57cec5SDimitry Andricinline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } 25290b57cec5SDimitry Andricinline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } 25300b57cec5SDimitry Andricinline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } 25310b57cec5SDimitry Andricinline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } 25320b57cec5SDimitry Andric 25330b57cec5SDimitry Andricinline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept 25340b57cec5SDimitry Andric : __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {} 25350b57cec5SDimitry Andric 25360b57cec5SDimitry Andricinline constexpr bool year_month_day::ok() const noexcept 25370b57cec5SDimitry Andric{ 25380b57cec5SDimitry Andric if (!__y.ok() || !__m.ok()) return false; 25390b57cec5SDimitry Andric return chrono::day{1} <= __d && __d <= (__y / __m / last).day(); 25400b57cec5SDimitry Andric} 25410b57cec5SDimitry Andric 25420b57cec5SDimitry Andricclass year_month_weekday { 25430b57cec5SDimitry Andric chrono::year __y; 25440b57cec5SDimitry Andric chrono::month __m; 25450b57cec5SDimitry Andric chrono::weekday_indexed __wdi; 25460b57cec5SDimitry Andricpublic: 25470b57cec5SDimitry Andric year_month_weekday() = default; 25480b57cec5SDimitry Andric constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval, 25490b57cec5SDimitry Andric const chrono::weekday_indexed& __wdival) noexcept 25500b57cec5SDimitry Andric : __y{__yval}, __m{__mval}, __wdi{__wdival} {} 25510b57cec5SDimitry Andric constexpr year_month_weekday(const sys_days& __sysd) noexcept 25520b57cec5SDimitry Andric : year_month_weekday(__from_days(__sysd.time_since_epoch())) {} 25530b57cec5SDimitry Andric inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept 25540b57cec5SDimitry Andric : year_month_weekday(__from_days(__locd.time_since_epoch())) {} 25550b57cec5SDimitry Andric constexpr year_month_weekday& operator+=(const months& m) noexcept; 25560b57cec5SDimitry Andric constexpr year_month_weekday& operator-=(const months& m) noexcept; 25570b57cec5SDimitry Andric constexpr year_month_weekday& operator+=(const years& y) noexcept; 25580b57cec5SDimitry Andric constexpr year_month_weekday& operator-=(const years& y) noexcept; 25590b57cec5SDimitry Andric 25600b57cec5SDimitry Andric inline constexpr chrono::year year() const noexcept { return __y; } 25610b57cec5SDimitry Andric inline constexpr chrono::month month() const noexcept { return __m; } 25620b57cec5SDimitry Andric inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); } 25630b57cec5SDimitry Andric inline constexpr unsigned index() const noexcept { return __wdi.index(); } 25640b57cec5SDimitry Andric inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; } 25650b57cec5SDimitry Andric 25660b57cec5SDimitry Andric inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } 25670b57cec5SDimitry Andric inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } 25680b57cec5SDimitry Andric inline constexpr bool ok() const noexcept 25690b57cec5SDimitry Andric { 25700b57cec5SDimitry Andric if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false; 25710b57cec5SDimitry Andric // TODO: make sure it's a valid date 25720b57cec5SDimitry Andric return true; 25730b57cec5SDimitry Andric } 25740b57cec5SDimitry Andric 25750b57cec5SDimitry Andric static constexpr year_month_weekday __from_days(days __d) noexcept; 25760b57cec5SDimitry Andric constexpr days __to_days() const noexcept; 25770b57cec5SDimitry Andric}; 25780b57cec5SDimitry Andric 25790b57cec5SDimitry Andricinline constexpr 25800b57cec5SDimitry Andricyear_month_weekday year_month_weekday::__from_days(days __d) noexcept 25810b57cec5SDimitry Andric{ 25820b57cec5SDimitry Andric const sys_days __sysd{__d}; 25830b57cec5SDimitry Andric const chrono::weekday __wd = chrono::weekday(__sysd); 25840b57cec5SDimitry Andric const year_month_day __ymd = year_month_day(__sysd); 25850b57cec5SDimitry Andric return year_month_weekday{__ymd.year(), __ymd.month(), 25860b57cec5SDimitry Andric __wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]}; 25870b57cec5SDimitry Andric} 25880b57cec5SDimitry Andric 25890b57cec5SDimitry Andricinline constexpr 25900b57cec5SDimitry Andricdays year_month_weekday::__to_days() const noexcept 25910b57cec5SDimitry Andric{ 25920b57cec5SDimitry Andric const sys_days __sysd = sys_days(__y/__m/1); 25930b57cec5SDimitry Andric return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7})) 25940b57cec5SDimitry Andric .time_since_epoch(); 25950b57cec5SDimitry Andric} 25960b57cec5SDimitry Andric 25970b57cec5SDimitry Andricinline constexpr 25980b57cec5SDimitry Andricbool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept 25990b57cec5SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); } 26000b57cec5SDimitry Andric 26010b57cec5SDimitry Andricinline constexpr 26020b57cec5SDimitry Andricbool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept 26030b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 26040b57cec5SDimitry Andric 26050b57cec5SDimitry Andricinline constexpr 26060b57cec5SDimitry Andricyear_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept 26070b57cec5SDimitry Andric{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; } 26080b57cec5SDimitry Andric 26090b57cec5SDimitry Andricinline constexpr 26100b57cec5SDimitry Andricyear_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept 26110b57cec5SDimitry Andric{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; } 26120b57cec5SDimitry Andric 26130b57cec5SDimitry Andricinline constexpr 26140b57cec5SDimitry Andricyear_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept 26150b57cec5SDimitry Andric{ return year(__lhs) / __rhs; } 26160b57cec5SDimitry Andric 26170b57cec5SDimitry Andricinline constexpr 26180b57cec5SDimitry Andricyear_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept 26190b57cec5SDimitry Andric{ return __rhs / __lhs; } 26200b57cec5SDimitry Andric 26210b57cec5SDimitry Andricinline constexpr 26220b57cec5SDimitry Andricyear_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept 26230b57cec5SDimitry Andric{ return year(__rhs) / __lhs; } 26240b57cec5SDimitry Andric 26250b57cec5SDimitry Andric 26260b57cec5SDimitry Andricinline constexpr 26270b57cec5SDimitry Andricyear_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept 26280b57cec5SDimitry Andric{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); } 26290b57cec5SDimitry Andric 26300b57cec5SDimitry Andricinline constexpr 26310b57cec5SDimitry Andricyear_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept 26320b57cec5SDimitry Andric{ return __rhs + __lhs; } 26330b57cec5SDimitry Andric 26340b57cec5SDimitry Andricinline constexpr 26350b57cec5SDimitry Andricyear_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept 26360b57cec5SDimitry Andric{ return __lhs + (-__rhs); } 26370b57cec5SDimitry Andric 26380b57cec5SDimitry Andricinline constexpr 26390b57cec5SDimitry Andricyear_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept 26400b57cec5SDimitry Andric{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; } 26410b57cec5SDimitry Andric 26420b57cec5SDimitry Andricinline constexpr 26430b57cec5SDimitry Andricyear_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept 26440b57cec5SDimitry Andric{ return __rhs + __lhs; } 26450b57cec5SDimitry Andric 26460b57cec5SDimitry Andricinline constexpr 26470b57cec5SDimitry Andricyear_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept 26480b57cec5SDimitry Andric{ return __lhs + (-__rhs); } 26490b57cec5SDimitry Andric 26500b57cec5SDimitry Andric 26510b57cec5SDimitry Andricinline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } 26520b57cec5SDimitry Andricinline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } 26530b57cec5SDimitry Andricinline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } 26540b57cec5SDimitry Andricinline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } 26550b57cec5SDimitry Andric 26560b57cec5SDimitry Andricclass year_month_weekday_last { 26570b57cec5SDimitry Andricprivate: 26580b57cec5SDimitry Andric chrono::year __y; 26590b57cec5SDimitry Andric chrono::month __m; 26600b57cec5SDimitry Andric chrono::weekday_last __wdl; 26610b57cec5SDimitry Andricpublic: 26620b57cec5SDimitry Andric constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval, 26630b57cec5SDimitry Andric const chrono::weekday_last& __wdlval) noexcept 26640b57cec5SDimitry Andric : __y{__yval}, __m{__mval}, __wdl{__wdlval} {} 26650b57cec5SDimitry Andric constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept; 26660b57cec5SDimitry Andric constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept; 26670b57cec5SDimitry Andric constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept; 26680b57cec5SDimitry Andric constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept; 26690b57cec5SDimitry Andric 26700b57cec5SDimitry Andric inline constexpr chrono::year year() const noexcept { return __y; } 26710b57cec5SDimitry Andric inline constexpr chrono::month month() const noexcept { return __m; } 26720b57cec5SDimitry Andric inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); } 26730b57cec5SDimitry Andric inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; } 26740b57cec5SDimitry Andric inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; } 26750b57cec5SDimitry Andric inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; } 26760b57cec5SDimitry Andric inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); } 26770b57cec5SDimitry Andric 26780b57cec5SDimitry Andric constexpr days __to_days() const noexcept; 26790b57cec5SDimitry Andric 26800b57cec5SDimitry Andric}; 26810b57cec5SDimitry Andric 26820b57cec5SDimitry Andricinline constexpr 26830b57cec5SDimitry Andricdays year_month_weekday_last::__to_days() const noexcept 26840b57cec5SDimitry Andric{ 26850b57cec5SDimitry Andric const sys_days __last = sys_days{__y/__m/last}; 26860b57cec5SDimitry Andric return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch(); 26870b57cec5SDimitry Andric 26880b57cec5SDimitry Andric} 26890b57cec5SDimitry Andric 26900b57cec5SDimitry Andricinline constexpr 26910b57cec5SDimitry Andricbool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept 26920b57cec5SDimitry Andric{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); } 26930b57cec5SDimitry Andric 26940b57cec5SDimitry Andricinline constexpr 26950b57cec5SDimitry Andricbool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept 26960b57cec5SDimitry Andric{ return !(__lhs == __rhs); } 26970b57cec5SDimitry Andric 26980b57cec5SDimitry Andric 26990b57cec5SDimitry Andricinline constexpr 27000b57cec5SDimitry Andricyear_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept 27010b57cec5SDimitry Andric{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; } 27020b57cec5SDimitry Andric 27030b57cec5SDimitry Andricinline constexpr 27040b57cec5SDimitry Andricyear_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept 27050b57cec5SDimitry Andric{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; } 27060b57cec5SDimitry Andric 27070b57cec5SDimitry Andricinline constexpr 27080b57cec5SDimitry Andricyear_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept 27090b57cec5SDimitry Andric{ return year(__lhs) / __rhs; } 27100b57cec5SDimitry Andric 27110b57cec5SDimitry Andricinline constexpr 27120b57cec5SDimitry Andricyear_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept 27130b57cec5SDimitry Andric{ return __rhs / __lhs; } 27140b57cec5SDimitry Andric 27150b57cec5SDimitry Andricinline constexpr 27160b57cec5SDimitry Andricyear_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept 27170b57cec5SDimitry Andric{ return year(__rhs) / __lhs; } 27180b57cec5SDimitry Andric 27190b57cec5SDimitry Andric 27200b57cec5SDimitry Andricinline constexpr 27210b57cec5SDimitry Andricyear_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept 27220b57cec5SDimitry Andric{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); } 27230b57cec5SDimitry Andric 27240b57cec5SDimitry Andricinline constexpr 27250b57cec5SDimitry Andricyear_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept 27260b57cec5SDimitry Andric{ return __rhs + __lhs; } 27270b57cec5SDimitry Andric 27280b57cec5SDimitry Andricinline constexpr 27290b57cec5SDimitry Andricyear_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept 27300b57cec5SDimitry Andric{ return __lhs + (-__rhs); } 27310b57cec5SDimitry Andric 27320b57cec5SDimitry Andricinline constexpr 27330b57cec5SDimitry Andricyear_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept 27340b57cec5SDimitry Andric{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; } 27350b57cec5SDimitry Andric 27360b57cec5SDimitry Andricinline constexpr 27370b57cec5SDimitry Andricyear_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept 27380b57cec5SDimitry Andric{ return __rhs + __lhs; } 27390b57cec5SDimitry Andric 27400b57cec5SDimitry Andricinline constexpr 27410b57cec5SDimitry Andricyear_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept 27420b57cec5SDimitry Andric{ return __lhs + (-__rhs); } 27430b57cec5SDimitry Andric 27440b57cec5SDimitry Andricinline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; } 27450b57cec5SDimitry Andricinline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; } 27460b57cec5SDimitry Andricinline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; } 27470b57cec5SDimitry Andricinline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; } 27480b57cec5SDimitry Andric 2749*e40139ffSDimitry Andric 2750*e40139ffSDimitry Andrictemplate <class _Duration> 2751*e40139ffSDimitry Andricclass hh_mm_ss 2752*e40139ffSDimitry Andric{ 2753*e40139ffSDimitry Andricprivate: 2754*e40139ffSDimitry Andric static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration"); 2755*e40139ffSDimitry Andric using __CommonType = common_type_t<_Duration, chrono::seconds>; 2756*e40139ffSDimitry Andric 2757*e40139ffSDimitry Andric static constexpr uint64_t __pow10(unsigned __exp) 2758*e40139ffSDimitry Andric { 2759*e40139ffSDimitry Andric uint64_t __ret = 1; 2760*e40139ffSDimitry Andric for (unsigned __i = 0; __i < __exp; ++__i) 2761*e40139ffSDimitry Andric __ret *= 10U; 2762*e40139ffSDimitry Andric return __ret; 2763*e40139ffSDimitry Andric } 2764*e40139ffSDimitry Andric 2765*e40139ffSDimitry Andric static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0) 2766*e40139ffSDimitry Andric { 2767*e40139ffSDimitry Andric if (__n >= 2 && __d != 0 && __w < 19) 2768*e40139ffSDimitry Andric return 1 + __width(__n, __d % __n * 10, __w+1); 2769*e40139ffSDimitry Andric return 0; 2770*e40139ffSDimitry Andric } 2771*e40139ffSDimitry Andric 2772*e40139ffSDimitry Andricpublic: 2773*e40139ffSDimitry Andric static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ? 2774*e40139ffSDimitry Andric __width(__CommonType::period::den) : 6u; 2775*e40139ffSDimitry Andric using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>; 2776*e40139ffSDimitry Andric 2777*e40139ffSDimitry Andric constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {} 2778*e40139ffSDimitry Andric 2779*e40139ffSDimitry Andric constexpr explicit hh_mm_ss(_Duration __d) noexcept : 2780*e40139ffSDimitry Andric __is_neg(__d < _Duration(0)), 2781*e40139ffSDimitry Andric __h(duration_cast<chrono::hours> (abs(__d))), 2782*e40139ffSDimitry Andric __m(duration_cast<chrono::minutes>(abs(__d) - hours())), 2783*e40139ffSDimitry Andric __s(duration_cast<chrono::seconds>(abs(__d) - hours() - minutes())), 2784*e40139ffSDimitry Andric __f(duration_cast<precision> (abs(__d) - hours() - minutes() - seconds())) 2785*e40139ffSDimitry Andric {} 2786*e40139ffSDimitry Andric 2787*e40139ffSDimitry Andric constexpr bool is_negative() const noexcept { return __is_neg; } 2788*e40139ffSDimitry Andric constexpr chrono::hours hours() const noexcept { return __h; } 2789*e40139ffSDimitry Andric constexpr chrono::minutes minutes() const noexcept { return __m; } 2790*e40139ffSDimitry Andric constexpr chrono::seconds seconds() const noexcept { return __s; } 2791*e40139ffSDimitry Andric constexpr precision subseconds() const noexcept { return __f; } 2792*e40139ffSDimitry Andric 2793*e40139ffSDimitry Andric constexpr precision to_duration() const noexcept 2794*e40139ffSDimitry Andric { 2795*e40139ffSDimitry Andric auto __dur = __h + __m + __s + __f; 2796*e40139ffSDimitry Andric return __is_neg ? -__dur : __dur; 2797*e40139ffSDimitry Andric } 2798*e40139ffSDimitry Andric 2799*e40139ffSDimitry Andric constexpr explicit operator precision() const noexcept { return to_duration(); } 2800*e40139ffSDimitry Andric 2801*e40139ffSDimitry Andricprivate: 2802*e40139ffSDimitry Andric bool __is_neg; 2803*e40139ffSDimitry Andric chrono::hours __h; 2804*e40139ffSDimitry Andric chrono::minutes __m; 2805*e40139ffSDimitry Andric chrono::seconds __s; 2806*e40139ffSDimitry Andric precision __f; 2807*e40139ffSDimitry Andric}; 2808*e40139ffSDimitry Andric 2809*e40139ffSDimitry Andricconstexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); } 2810*e40139ffSDimitry Andricconstexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); } 2811*e40139ffSDimitry Andric 2812*e40139ffSDimitry Andricconstexpr hours make12(const hours& __h) noexcept 2813*e40139ffSDimitry Andric{ 2814*e40139ffSDimitry Andric if (__h == hours( 0)) return hours(12); 2815*e40139ffSDimitry Andric else if (__h <= hours(12)) return __h; 2816*e40139ffSDimitry Andric else return __h - hours(12); 2817*e40139ffSDimitry Andric} 2818*e40139ffSDimitry Andric 2819*e40139ffSDimitry Andricconstexpr hours make24(const hours& __h, bool __is_pm) noexcept 2820*e40139ffSDimitry Andric{ 2821*e40139ffSDimitry Andric if (__is_pm) 2822*e40139ffSDimitry Andric return __h == hours(12) ? __h : __h + hours(12); 2823*e40139ffSDimitry Andric else 2824*e40139ffSDimitry Andric return __h == hours(12) ? hours(0) : __h; 2825*e40139ffSDimitry Andric} 2826*e40139ffSDimitry Andric 28270b57cec5SDimitry Andric#endif // _LIBCPP_STD_VER > 17 28280b57cec5SDimitry Andric} // chrono 28290b57cec5SDimitry Andric 28300b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 28310b57cec5SDimitry Andric// Suffixes for duration literals [time.duration.literals] 28320b57cec5SDimitry Andricinline namespace literals 28330b57cec5SDimitry Andric{ 28340b57cec5SDimitry Andric inline namespace chrono_literals 28350b57cec5SDimitry Andric { 28360b57cec5SDimitry Andric 28370b57cec5SDimitry Andric constexpr chrono::hours operator""h(unsigned long long __h) 28380b57cec5SDimitry Andric { 28390b57cec5SDimitry Andric return chrono::hours(static_cast<chrono::hours::rep>(__h)); 28400b57cec5SDimitry Andric } 28410b57cec5SDimitry Andric 28420b57cec5SDimitry Andric constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h) 28430b57cec5SDimitry Andric { 28440b57cec5SDimitry Andric return chrono::duration<long double, ratio<3600,1>>(__h); 28450b57cec5SDimitry Andric } 28460b57cec5SDimitry Andric 28470b57cec5SDimitry Andric 28480b57cec5SDimitry Andric constexpr chrono::minutes operator""min(unsigned long long __m) 28490b57cec5SDimitry Andric { 28500b57cec5SDimitry Andric return chrono::minutes(static_cast<chrono::minutes::rep>(__m)); 28510b57cec5SDimitry Andric } 28520b57cec5SDimitry Andric 28530b57cec5SDimitry Andric constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m) 28540b57cec5SDimitry Andric { 28550b57cec5SDimitry Andric return chrono::duration<long double, ratio<60,1>> (__m); 28560b57cec5SDimitry Andric } 28570b57cec5SDimitry Andric 28580b57cec5SDimitry Andric 28590b57cec5SDimitry Andric constexpr chrono::seconds operator""s(unsigned long long __s) 28600b57cec5SDimitry Andric { 28610b57cec5SDimitry Andric return chrono::seconds(static_cast<chrono::seconds::rep>(__s)); 28620b57cec5SDimitry Andric } 28630b57cec5SDimitry Andric 28640b57cec5SDimitry Andric constexpr chrono::duration<long double> operator""s(long double __s) 28650b57cec5SDimitry Andric { 28660b57cec5SDimitry Andric return chrono::duration<long double> (__s); 28670b57cec5SDimitry Andric } 28680b57cec5SDimitry Andric 28690b57cec5SDimitry Andric 28700b57cec5SDimitry Andric constexpr chrono::milliseconds operator""ms(unsigned long long __ms) 28710b57cec5SDimitry Andric { 28720b57cec5SDimitry Andric return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms)); 28730b57cec5SDimitry Andric } 28740b57cec5SDimitry Andric 28750b57cec5SDimitry Andric constexpr chrono::duration<long double, milli> operator""ms(long double __ms) 28760b57cec5SDimitry Andric { 28770b57cec5SDimitry Andric return chrono::duration<long double, milli>(__ms); 28780b57cec5SDimitry Andric } 28790b57cec5SDimitry Andric 28800b57cec5SDimitry Andric 28810b57cec5SDimitry Andric constexpr chrono::microseconds operator""us(unsigned long long __us) 28820b57cec5SDimitry Andric { 28830b57cec5SDimitry Andric return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us)); 28840b57cec5SDimitry Andric } 28850b57cec5SDimitry Andric 28860b57cec5SDimitry Andric constexpr chrono::duration<long double, micro> operator""us(long double __us) 28870b57cec5SDimitry Andric { 28880b57cec5SDimitry Andric return chrono::duration<long double, micro> (__us); 28890b57cec5SDimitry Andric } 28900b57cec5SDimitry Andric 28910b57cec5SDimitry Andric 28920b57cec5SDimitry Andric constexpr chrono::nanoseconds operator""ns(unsigned long long __ns) 28930b57cec5SDimitry Andric { 28940b57cec5SDimitry Andric return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns)); 28950b57cec5SDimitry Andric } 28960b57cec5SDimitry Andric 28970b57cec5SDimitry Andric constexpr chrono::duration<long double, nano> operator""ns(long double __ns) 28980b57cec5SDimitry Andric { 28990b57cec5SDimitry Andric return chrono::duration<long double, nano> (__ns); 29000b57cec5SDimitry Andric } 29010b57cec5SDimitry Andric 29020b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS) 29030b57cec5SDimitry Andric constexpr chrono::day operator ""d(unsigned long long __d) noexcept 29040b57cec5SDimitry Andric { 29050b57cec5SDimitry Andric return chrono::day(static_cast<unsigned>(__d)); 29060b57cec5SDimitry Andric } 29070b57cec5SDimitry Andric 29080b57cec5SDimitry Andric constexpr chrono::year operator ""y(unsigned long long __y) noexcept 29090b57cec5SDimitry Andric { 29100b57cec5SDimitry Andric return chrono::year(static_cast<int>(__y)); 29110b57cec5SDimitry Andric } 29120b57cec5SDimitry Andric#endif 29130b57cec5SDimitry Andric}} 29140b57cec5SDimitry Andric 29150b57cec5SDimitry Andricnamespace chrono { // hoist the literals into namespace std::chrono 29160b57cec5SDimitry Andric using namespace literals::chrono_literals; 29170b57cec5SDimitry Andric} 29180b57cec5SDimitry Andric 29190b57cec5SDimitry Andric#endif 29200b57cec5SDimitry Andric 29210b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 29220b57cec5SDimitry Andric 29230b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 29240b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM 29250b57cec5SDimitry Andricstruct _FilesystemClock { 29260b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_INT128) 29270b57cec5SDimitry Andric typedef __int128_t rep; 29280b57cec5SDimitry Andric typedef nano period; 29290b57cec5SDimitry Andric#else 29300b57cec5SDimitry Andric typedef long long rep; 29310b57cec5SDimitry Andric typedef nano period; 29320b57cec5SDimitry Andric#endif 29330b57cec5SDimitry Andric 29340b57cec5SDimitry Andric typedef chrono::duration<rep, period> duration; 29350b57cec5SDimitry Andric typedef chrono::time_point<_FilesystemClock> time_point; 29360b57cec5SDimitry Andric 2937*e40139ffSDimitry Andric _LIBCPP_EXPORTED_FROM_ABI 29380b57cec5SDimitry Andric static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false; 29390b57cec5SDimitry Andric 29400b57cec5SDimitry Andric _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept; 29410b57cec5SDimitry Andric 29420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 29430b57cec5SDimitry Andric static time_t to_time_t(const time_point& __t) noexcept { 29440b57cec5SDimitry Andric typedef chrono::duration<rep> __secs; 29450b57cec5SDimitry Andric return time_t( 29460b57cec5SDimitry Andric chrono::duration_cast<__secs>(__t.time_since_epoch()).count()); 29470b57cec5SDimitry Andric } 29480b57cec5SDimitry Andric 29490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY 29500b57cec5SDimitry Andric static time_point from_time_t(time_t __t) noexcept { 29510b57cec5SDimitry Andric typedef chrono::duration<rep> __secs; 29520b57cec5SDimitry Andric return time_point(__secs(__t)); 29530b57cec5SDimitry Andric } 29540b57cec5SDimitry Andric}; 29550b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_FILESYSTEM 29560b57cec5SDimitry Andric#endif // !_LIBCPP_CXX03_LANG 29570b57cec5SDimitry Andric 29580b57cec5SDimitry Andric_LIBCPP_POP_MACROS 29590b57cec5SDimitry Andric 29600b57cec5SDimitry Andric#endif // _LIBCPP_CHRONO 2961