// -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP_CHRONO #define _LIBCPP_CHRONO /* chrono synopsis namespace std { namespace chrono { template constexpr ToDuration duration_cast(const duration& fd); template struct treat_as_floating_point : is_floating_point {}; template inline constexpr bool treat_as_floating_point_v = treat_as_floating_point::value; // C++17 template struct duration_values { public: static constexpr Rep zero(); // noexcept in C++20 static constexpr Rep max(); // noexcept in C++20 static constexpr Rep min(); // noexcept in C++20 }; // duration template > class duration { static_assert(!__is_duration::value, "A duration representation can not be a duration"); static_assert(__is_ratio::value, "Second template parameter of duration must be a std::ratio"); static_assert(Period::num > 0, "duration period must be positive"); public: typedef Rep rep; typedef typename _Period::type period; constexpr duration() = default; template constexpr explicit duration(const Rep2& r, typename enable_if < is_convertible::value && (treat_as_floating_point::value || !treat_as_floating_point::value && !treat_as_floating_point::value) >::type* = 0); // conversions template constexpr duration(const duration& d, typename enable_if < treat_as_floating_point::value || ratio_divide::type::den == 1 >::type* = 0); // observer constexpr rep count() const; // arithmetic constexpr common_type::type operator+() const; constexpr common_type::type operator-() const; constexpr duration& operator++(); // constexpr in C++17 constexpr duration operator++(int); // constexpr in C++17 constexpr duration& operator--(); // constexpr in C++17 constexpr duration operator--(int); // constexpr in C++17 constexpr duration& operator+=(const duration& d); // constexpr in C++17 constexpr duration& operator-=(const duration& d); // constexpr in C++17 duration& operator*=(const rep& rhs); // constexpr in C++17 duration& operator/=(const rep& rhs); // constexpr in C++17 duration& operator%=(const rep& rhs); // constexpr in C++17 duration& operator%=(const duration& rhs); // constexpr in C++17 // special values static constexpr duration zero(); // noexcept in C++20 static constexpr duration min(); // noexcept in C++20 static constexpr duration max(); // noexcept in C++20 }; typedef duration nanoseconds; typedef duration microseconds; typedef duration milliseconds; typedef duration seconds; typedef duration< long, ratio< 60> > minutes; typedef duration< long, ratio<3600> > hours; template class time_point { public: typedef Clock clock; typedef Duration duration; typedef typename duration::rep rep; typedef typename duration::period period; private: duration d_; // exposition only public: time_point(); // has value "epoch" // constexpr in C++14 explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14 // conversions template time_point(const time_point& t); // constexpr in C++14 // observer duration time_since_epoch() const; // constexpr in C++14 // arithmetic time_point& operator+=(const duration& d); // constexpr in C++17 time_point& operator-=(const duration& d); // constexpr in C++17 // special values static constexpr time_point min(); // noexcept in C++20 static constexpr time_point max(); // noexcept in C++20 }; } // chrono // common_type traits template struct common_type, chrono::duration>; template struct common_type, chrono::time_point>; namespace chrono { // duration arithmetic template constexpr typename common_type, duration>::type operator+(const duration& lhs, const duration& rhs); template constexpr typename common_type, duration>::type operator-(const duration& lhs, const duration& rhs); template constexpr duration::type, Period> operator*(const duration& d, const Rep2& s); template constexpr duration::type, Period> operator*(const Rep1& s, const duration& d); template constexpr duration::type, Period> operator/(const duration& d, const Rep2& s); template constexpr typename common_type::type operator/(const duration& lhs, const duration& rhs); // duration comparisons template constexpr bool operator==(const duration& lhs, const duration& rhs); template constexpr bool operator!=(const duration& lhs, const duration& rhs); template constexpr bool operator< (const duration& lhs, const duration& rhs); template constexpr bool operator<=(const duration& lhs, const duration& rhs); template constexpr bool operator> (const duration& lhs, const duration& rhs); template constexpr bool operator>=(const duration& lhs, const duration& rhs); // duration_cast template ToDuration duration_cast(const duration& d); template constexpr ToDuration floor(const duration& d); // C++17 template constexpr ToDuration ceil(const duration& d); // C++17 template constexpr ToDuration round(const duration& d); // C++17 // duration I/O is elsewhere // time_point arithmetic (all constexpr in C++14) template time_point>::type> operator+(const time_point& lhs, const duration& rhs); template time_point, Duration2>::type> operator+(const duration& lhs, const time_point& rhs); template time_point>::type> operator-(const time_point& lhs, const duration& rhs); template typename common_type::type operator-(const time_point& lhs, const time_point& rhs); // time_point comparisons (all constexpr in C++14) template bool operator==(const time_point& lhs, const time_point& rhs); template bool operator!=(const time_point& lhs, const time_point& rhs); template bool operator< (const time_point& lhs, const time_point& rhs); template bool operator<=(const time_point& lhs, const time_point& rhs); template bool operator> (const time_point& lhs, const time_point& rhs); template bool operator>=(const time_point& lhs, const time_point& rhs); // time_point_cast (constexpr in C++14) template time_point time_point_cast(const time_point& t); template constexpr time_point floor(const time_point& tp); // C++17 template constexpr time_point ceil(const time_point& tp); // C++17 template constexpr time_point round(const time_point& tp); // C++17 template constexpr duration abs(duration d); // C++17 // Clocks class system_clock { public: typedef microseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; static const bool is_steady = false; // constexpr in C++14 static time_point now() noexcept; static time_t to_time_t (const time_point& __t) noexcept; static time_point from_time_t(time_t __t) noexcept; }; template using sys_time = time_point; // C++20 using sys_seconds = sys_time; // C++20 using sys_days = sys_time; // C++20 class file_clock // C++20 { public: typedef see-below rep; typedef nano period; typedef chrono::duration duration; typedef chrono::time_point time_point; static constexpr bool is_steady = false; static time_point now() noexcept; template static sys_time to_sys(const file_time&); template static file_time from_sys(const sys_time&); }; template using file_time = time_point; // C++20 class steady_clock { public: typedef nanoseconds duration; typedef duration::rep rep; typedef duration::period period; typedef chrono::time_point time_point; static const bool is_steady = true; // constexpr in C++14 static time_point now() noexcept; }; typedef steady_clock high_resolution_clock; // 25.7.8, local time // C++20 struct local_t {}; template using local_time = time_point; using local_seconds = local_time; using local_days = local_time; // 25.8.2, class last_spec // C++20 struct last_spec; // 25.8.3, class day // C++20 class day; constexpr bool operator==(const day& x, const day& y) noexcept; constexpr bool operator!=(const day& x, const day& y) noexcept; constexpr bool operator< (const day& x, const day& y) noexcept; constexpr bool operator> (const day& x, const day& y) noexcept; constexpr bool operator<=(const day& x, const day& y) noexcept; constexpr bool operator>=(const day& x, const day& y) noexcept; constexpr day operator+(const day& x, const days& y) noexcept; constexpr day operator+(const days& x, const day& y) noexcept; constexpr day operator-(const day& x, const days& y) noexcept; constexpr days operator-(const day& x, const day& y) noexcept; // 25.8.4, class month // C++20 class month; constexpr bool operator==(const month& x, const month& y) noexcept; constexpr bool operator!=(const month& x, const month& y) noexcept; constexpr bool operator< (const month& x, const month& y) noexcept; constexpr bool operator> (const month& x, const month& y) noexcept; constexpr bool operator<=(const month& x, const month& y) noexcept; constexpr bool operator>=(const month& x, const month& y) noexcept; constexpr month operator+(const month& x, const months& y) noexcept; constexpr month operator+(const months& x, const month& y) noexcept; constexpr month operator-(const month& x, const months& y) noexcept; constexpr months operator-(const month& x, const month& y) noexcept; // 25.8.5, class year // C++20 class year; constexpr bool operator==(const year& x, const year& y) noexcept; constexpr bool operator!=(const year& x, const year& y) noexcept; constexpr bool operator< (const year& x, const year& y) noexcept; constexpr bool operator> (const year& x, const year& y) noexcept; constexpr bool operator<=(const year& x, const year& y) noexcept; constexpr bool operator>=(const year& x, const year& y) noexcept; constexpr year operator+(const year& x, const years& y) noexcept; constexpr year operator+(const years& x, const year& y) noexcept; constexpr year operator-(const year& x, const years& y) noexcept; constexpr years operator-(const year& x, const year& y) noexcept; // 25.8.6, class weekday // C++20 class weekday; constexpr bool operator==(const weekday& x, const weekday& y) noexcept; constexpr bool operator!=(const weekday& x, const weekday& y) noexcept; constexpr weekday operator+(const weekday& x, const days& y) noexcept; constexpr weekday operator+(const days& x, const weekday& y) noexcept; constexpr weekday operator-(const weekday& x, const days& y) noexcept; constexpr days operator-(const weekday& x, const weekday& y) noexcept; // 25.8.7, class weekday_indexed // C++20 class weekday_indexed; constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept; constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept; // 25.8.8, class weekday_last // C++20 class weekday_last; constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept; constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept; // 25.8.9, class month_day // C++20 class month_day; constexpr bool operator==(const month_day& x, const month_day& y) noexcept; constexpr bool operator!=(const month_day& x, const month_day& y) noexcept; constexpr bool operator< (const month_day& x, const month_day& y) noexcept; constexpr bool operator> (const month_day& x, const month_day& y) noexcept; constexpr bool operator<=(const month_day& x, const month_day& y) noexcept; constexpr bool operator>=(const month_day& x, const month_day& y) noexcept; // 25.8.10, class month_day_last // C++20 class month_day_last; constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept; constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept; // 25.8.11, class month_weekday // C++20 class month_weekday; constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept; constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept; // 25.8.12, class month_weekday_last // C++20 class month_weekday_last; constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept; constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept; // 25.8.13, class year_month // C++20 class year_month; constexpr bool operator==(const year_month& x, const year_month& y) noexcept; constexpr bool operator!=(const year_month& x, const year_month& y) noexcept; constexpr bool operator< (const year_month& x, const year_month& y) noexcept; constexpr bool operator> (const year_month& x, const year_month& y) noexcept; constexpr bool operator<=(const year_month& x, const year_month& y) noexcept; constexpr bool operator>=(const year_month& x, const year_month& y) noexcept; constexpr year_month operator+(const year_month& ym, const months& dm) noexcept; constexpr year_month operator+(const months& dm, const year_month& ym) noexcept; constexpr year_month operator-(const year_month& ym, const months& dm) noexcept; constexpr months operator-(const year_month& x, const year_month& y) noexcept; constexpr year_month operator+(const year_month& ym, const years& dy) noexcept; constexpr year_month operator+(const years& dy, const year_month& ym) noexcept; constexpr year_month operator-(const year_month& ym, const years& dy) noexcept; // 25.8.14, class year_month_day class // C++20 year_month_day; constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept; constexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept; constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept; constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept; constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept; constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept; constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; // 25.8.15, class year_month_day_last // C++20 class year_month_day_last; constexpr bool operator==(const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator!=(const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator< (const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator> (const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator<=(const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr bool operator>=(const year_month_day_last& x, const year_month_day_last& y) noexcept; constexpr year_month_day_last operator+(const year_month_day_last& ymdl, const months& dm) noexcept; constexpr year_month_day_last operator+(const months& dm, const year_month_day_last& ymdl) noexcept; constexpr year_month_day_last operator+(const year_month_day_last& ymdl, const years& dy) noexcept; constexpr year_month_day_last operator+(const years& dy, const year_month_day_last& ymdl) noexcept; constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const months& dm) noexcept; constexpr year_month_day_last operator-(const year_month_day_last& ymdl, const years& dy) noexcept; // 25.8.16, class year_month_weekday // C++20 class year_month_weekday; constexpr bool operator==(const year_month_weekday& x, const year_month_weekday& y) noexcept; constexpr bool operator!=(const year_month_weekday& x, const year_month_weekday& y) noexcept; constexpr year_month_weekday operator+(const year_month_weekday& ymwd, const months& dm) noexcept; constexpr year_month_weekday operator+(const months& dm, const year_month_weekday& ymwd) noexcept; constexpr year_month_weekday operator+(const year_month_weekday& ymwd, const years& dy) noexcept; constexpr year_month_weekday operator+(const years& dy, const year_month_weekday& ymwd) noexcept; constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const months& dm) noexcept; constexpr year_month_weekday operator-(const year_month_weekday& ymwd, const years& dy) noexcept; // 25.8.17, class year_month_weekday_last // C++20 class year_month_weekday_last; constexpr bool operator==(const year_month_weekday_last& x, const year_month_weekday_last& y) noexcept; constexpr bool operator!=(const year_month_weekday_last& x, const year_month_weekday_last& y) noexcept; constexpr year_month_weekday_last operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept; constexpr year_month_weekday_last operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept; constexpr year_month_weekday_last operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept; constexpr year_month_weekday_last operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept; constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept; constexpr year_month_weekday_last operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept; // 25.8.18, civil calendar conventional syntax operators // C++20 constexpr year_month operator/(const year& y, const month& m) noexcept; constexpr year_month operator/(const year& y, int m) noexcept; constexpr month_day operator/(const month& m, const day& d) noexcept; constexpr month_day operator/(const month& m, int d) noexcept; constexpr month_day operator/(int m, const day& d) noexcept; constexpr month_day operator/(const day& d, const month& m) noexcept; constexpr month_day operator/(const day& d, int m) noexcept; constexpr month_day_last operator/(const month& m, last_spec) noexcept; constexpr month_day_last operator/(int m, last_spec) noexcept; constexpr month_day_last operator/(last_spec, const month& m) noexcept; constexpr month_day_last operator/(last_spec, int m) noexcept; constexpr month_weekday operator/(const month& m, const weekday_indexed& wdi) noexcept; constexpr month_weekday operator/(int m, const weekday_indexed& wdi) noexcept; constexpr month_weekday operator/(const weekday_indexed& wdi, const month& m) noexcept; constexpr month_weekday operator/(const weekday_indexed& wdi, int m) noexcept; constexpr month_weekday_last operator/(const month& m, const weekday_last& wdl) noexcept; constexpr month_weekday_last operator/(int m, const weekday_last& wdl) noexcept; constexpr month_weekday_last operator/(const weekday_last& wdl, const month& m) noexcept; constexpr month_weekday_last operator/(const weekday_last& wdl, int m) noexcept; constexpr year_month_day operator/(const year_month& ym, const day& d) noexcept; constexpr year_month_day operator/(const year_month& ym, int d) noexcept; constexpr year_month_day operator/(const year& y, const month_day& md) noexcept; constexpr year_month_day operator/(int y, const month_day& md) noexcept; constexpr year_month_day operator/(const month_day& md, const year& y) noexcept; constexpr year_month_day operator/(const month_day& md, int y) noexcept; constexpr year_month_day_last operator/(const year_month& ym, last_spec) noexcept; constexpr year_month_day_last operator/(const year& y, const month_day_last& mdl) noexcept; constexpr year_month_day_last operator/(int y, const month_day_last& mdl) noexcept; constexpr year_month_day_last operator/(const month_day_last& mdl, const year& y) noexcept; constexpr year_month_day_last operator/(const month_day_last& mdl, int y) noexcept; constexpr year_month_weekday operator/(const year_month& ym, const weekday_indexed& wdi) noexcept; constexpr year_month_weekday operator/(const year& y, const month_weekday& mwd) noexcept; constexpr year_month_weekday operator/(int y, const month_weekday& mwd) noexcept; constexpr year_month_weekday operator/(const month_weekday& mwd, const year& y) noexcept; constexpr year_month_weekday operator/(const month_weekday& mwd, int y) noexcept; constexpr year_month_weekday_last operator/(const year_month& ym, const weekday_last& wdl) noexcept; constexpr year_month_weekday_last operator/(const year& y, const month_weekday_last& mwdl) noexcept; constexpr year_month_weekday_last operator/(int y, const month_weekday_last& mwdl) noexcept; constexpr year_month_weekday_last operator/(const month_weekday_last& mwdl, const year& y) noexcept; constexpr year_month_weekday_last operator/(const month_weekday_last& mwdl, int y) noexcept; // 26.9, class template hh_mm_ss template class hh_mm_ss { bool is_neg; // exposition only chrono::hours h; // exposition only chrono::minutes m; // exposition only chrono::seconds s; // exposition only precision ss; // exposition only public: static unsigned constexpr fractional_width = see below; using precision = see below; constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {} constexpr explicit hh_mm_ss(Duration d) noexcept; constexpr bool is_negative() const noexcept; constexpr chrono::hours hours() const noexcept; constexpr chrono::minutes minutes() const noexcept; constexpr chrono::seconds seconds() const noexcept; constexpr precision subseconds() const noexcept; constexpr explicit operator precision() const noexcept; constexpr precision to_duration() const noexcept; }; // 26.10, 12/24 hour functions constexpr bool is_am(hours const& h) noexcept; constexpr bool is_pm(hours const& h) noexcept; constexpr hours make12(const hours& h) noexcept; constexpr hours make24(const hours& h, bool is_pm) noexcept; // 25.10.5, class time_zone // C++20 enum class choose {earliest, latest}; class time_zone; bool operator==(const time_zone& x, const time_zone& y) noexcept; bool operator!=(const time_zone& x, const time_zone& y) noexcept; bool operator<(const time_zone& x, const time_zone& y) noexcept; bool operator>(const time_zone& x, const time_zone& y) noexcept; bool operator<=(const time_zone& x, const time_zone& y) noexcept; bool operator>=(const time_zone& x, const time_zone& y) noexcept; // calendrical constants inline constexpr last_spec last{}; // C++20 inline constexpr chrono::weekday Sunday{0}; // C++20 inline constexpr chrono::weekday Monday{1}; // C++20 inline constexpr chrono::weekday Tuesday{2}; // C++20 inline constexpr chrono::weekday Wednesday{3}; // C++20 inline constexpr chrono::weekday Thursday{4}; // C++20 inline constexpr chrono::weekday Friday{5}; // C++20 inline constexpr chrono::weekday Saturday{6}; // C++20 inline constexpr chrono::month January{1}; // C++20 inline constexpr chrono::month February{2}; // C++20 inline constexpr chrono::month March{3}; // C++20 inline constexpr chrono::month April{4}; // C++20 inline constexpr chrono::month May{5}; // C++20 inline constexpr chrono::month June{6}; // C++20 inline constexpr chrono::month July{7}; // C++20 inline constexpr chrono::month August{8}; // C++20 inline constexpr chrono::month September{9}; // C++20 inline constexpr chrono::month October{10}; // C++20 inline constexpr chrono::month November{11}; // C++20 inline constexpr chrono::month December{12}; // C++20 } // chrono inline namespace literals { inline namespace chrono_literals { constexpr chrono::hours operator ""h(unsigned long long); // C++14 constexpr chrono::duration> operator ""h(long double); // C++14 constexpr chrono::minutes operator ""min(unsigned long long); // C++14 constexpr chrono::duration> operator ""min(long double); // C++14 constexpr chrono::seconds operator ""s(unsigned long long); // C++14 constexpr chrono::duration operator ""s(long double); // C++14 constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14 constexpr chrono::duration operator ""ms(long double); // C++14 constexpr chrono::microseconds operator ""us(unsigned long long); // C++14 constexpr chrono::duration operator ""us(long double); // C++14 constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14 constexpr chrono::duration operator ""ns(long double); // C++14 constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20 constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20 } // chrono_literals } // literals } // std */ #include <__chrono/calendar.h> #include <__chrono/convert_to_timespec.h> #include <__chrono/duration.h> #include <__chrono/file_clock.h> #include <__chrono/high_resolution_clock.h> #include <__chrono/steady_clock.h> #include <__chrono/system_clock.h> #include <__chrono/time_point.h> #include <__config> #include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif #endif // _LIBCPP_CHRONO