std::chrono(3)

πŸ’– std::chrono(3) πŸ’–

okay bestie, welcome to std::chrono(3) from the Library Functions Manual. this whole page is literally the ISO C++ 2011 namespace for date and time utilities. no cap. it's part 1, so we're just getting started. πŸŽ€


✨ NAME ✨

std::chrono β€” ISO C++ 2011 namespace for date and time utilities.


🌈 SYNOPSIS 🌈

πŸ‘‘ Classes

  • class duration β€” chrono::duration represents a distance between two points in time. it's giving "how long though?" energy. πŸ’…
  • struct duration_values β€” duration_values. that's the whole description, bestie. short and iconic.
  • class gps_clock β€” no extra description in the original, just the class name. it's mysterious like that. πŸ¦‹
  • class hh_mm_ss β€” also no description attached. just vibes. ✨
  • struct steady_clock β€” Monotonic clock. periodt.
  • struct system_clock β€” System clock. yep.
  • class tai_clock β€” no description. it's just there, being a clock. πŸ•°οΈ
  • class time_point β€” chrono::time_point represents a point in time as measured by a clock. so it's a timestamp with main character energy. πŸ‘‘
  • struct treat_as_floating_point β€” no description, just the struct name. ok.
  • class tzdb_list β€” no description. tzdb said what it said. πŸ’€
  • class utc_clock β€” no description. utc clock is utc clocking. 🌍

🌸 Typedefs

  • using days β€” days. that's it. that's the typedef. πŸ’–
  • using file_clock β€” no description attached.
  • template<typename _Duration> using file_time β€” no description attached.
  • using gps_seconds β€” no description attached.
  • template<typename _Duration> using gps_time β€” no description attached.
  • using high_resolution_clock β€” Highest-resolution clock. periodt.
  • using hours β€” hours. iconic.
  • using local_days β€” no description attached.
  • using local_seconds β€” no description attached.
  • template<typename _Duration> using local_time β€” no description attached.
  • using microseconds β€” microseconds. tiny but mighty. 🧚
  • using milliseconds β€” milliseconds. slay.
  • using minutes β€” minutes. yes bestie.
  • using months β€” months. calendar energy. πŸ“…
  • using nanoseconds β€” nanoseconds. so smol. πŸ“
  • using seconds β€” seconds. the classic.
  • using sys_days β€” no description attached.
  • using sys_seconds β€” no description attached.
  • template<typename _Duration> using sys_time β€” no description attached.
  • using tai_seconds β€” no description attached.
  • template<typename _Duration> using tai_time β€” no description attached.
  • using utc_seconds β€” no description attached.
  • template<typename _Duration> using utc_time β€” no description attached.
  • using weeks β€” weeks. that's the typedef. πŸ—“οΈ
  • using years β€” years. periodt. πŸ’œ
  • using zoned_seconds β€” no description attached.

πŸŽ€ Enumerations

  • enum class choose { earliest, latest } β€” no description attached, just the enum and its two values. periodt.

✨ Functions ✨

okay bestie, here's the full function lineup β€” every single one, no skips. πŸ’…

  • abs ✨
       template<typename _Rep, typename _Period> constexpr enable_if_t<
           numeric_limits< _Rep >::is_signed, duration< _Rep, _Period > > abs
           (duration< _Rep, _Period > __d)
  • ceil (for duration) πŸ¦‹
       template<typename _ToDur, typename _Rep, typename _Period> constexpr
           __enable_if_is_duration< _ToDur > ceil (const duration< _Rep,
           _Period > &__d)
  • ceil (for time_point) πŸ¦‹
       template<typename _ToDur, typename _Clock, typename _Dur> constexpr
           enable_if_t< __is_duration_v< _ToDur >, time_point< _Clock, _ToDur >
           > ceil (const time_point< _Clock, _Dur > &__tp)
  • clock_cast πŸ”₯
       template<typename _DestClock, typename _SourceClock, typename _Duration>
           requires __detail::__clock_convs<_DestClock, _SourceClock,
           _Duration> || __detail::__clock_convs_sys<_DestClock, _SourceClock,
           _Duration> || __detail::__clock_convs_utc<_DestClock, _SourceClock,
           _Duration> || __detail::__clock_convs_sys_utc<_DestClock,
           _SourceClock, _Duration> ||
           __detail::__clock_convs_utc_sys<_DestClock, _SourceClock,
           _Duration>auto clock_cast (const time_point< _SourceClock, _Duration
           > &__t)"

Convert a time point to a different clock. it's giving time zone traveler energy ✈️

  • current_zone 🌈
       const time_zone * current_zone ()
  • duration_cast πŸ’š
       template<typename _ToDur, typename _Rep, typename _Period> constexpr
           __enable_if_is_duration< _ToDur > duration_cast (const duration<
           _Rep, _Period > &__d)
  • floor (for duration) ⭐
       template<typename _ToDur, typename _Rep, typename _Period> constexpr
           __enable_if_is_duration< _ToDur > floor (const duration< _Rep,
           _Period > &__d)
  • floor (for time_point) ⭐
       template<typename _ToDur, typename _Clock, typename _Dur> constexpr
           enable_if_t< __is_duration_v< _ToDur >, time_point< _Clock, _ToDur >
           > floor (const time_point< _Clock, _Dur > &__tp)
  • from_stream (for day) πŸ‘
       template<typename _CharT, typename _Traits, typename _Alloc =
           allocator<_CharT>> basic_istream< _CharT, _Traits > & from_stream
           (basic_istream< _CharT, _Traits > &__is, const _CharT *__fmt, day
           &__d, basic_string< _CharT, _Traits, _Alloc > *__abbrev=nullptr,
           minutes *__offset=nullptr)
  • from_stream (for duration) πŸ‘
       template<typename _CharT, typename _Traits, typename _Rep, typename
           _Period, typename _Alloc = allocator<_CharT>> basic_istream< _CharT,
           _Traits > & from_stream (basic_istream< _CharT, _Traits > &__is,
           const _CharT *__fmt, duration< _Rep, _Period > &__d, basic_string<
           _CharT, _Traits, _Alloc > *__abbrev=nullptr, minutes
           *__offset=nullptr)
  • from_stream (for file_time) πŸ‘
       template<typename _CharT, typename _Traits, typename _Duration, typename
           _Alloc = allocator<_CharT>> basic_istream< _CharT, _Traits > &
           from_stream (basic_istream< _CharT, _Traits > &__is, const _CharT
           *__fmt, file_time< _Duration > &__tp, basic_string< _CharT, _Traits,
           _Alloc > *__abbrev=nullptr, minutes *__offset=nullptr)
  • from_stream (for gps_time) πŸ‘
       template<typename _CharT, typename _Traits, typename _Duration, typename
           _Alloc = allocator<_CharT>> basic_istream< _CharT, _Traits > &
           from_stream (basic_istream< _CharT, _Traits > &__is, const _CharT
           *__fmt, gps_time< _Duration > &__tp, basic_string< _CharT, _Traits,
           _Alloc > *__abbrev=nullptr, minutes *__offset=nullptr)
  • from_stream (for local_time) πŸ‘
       template<typename _CharT, typename _Traits, typename _Duration, typename
           _Alloc = allocator<_CharT>> basic_istream< _CharT, _Traits > &
           from_stream (basic_istream< _CharT, _Traits > &__is, const _CharT
           *__fmt, local_time< _Duration > &__tp, basic_string< _CharT,
           _Traits, _Alloc > *__abbrev=nullptr, minutes *__offset=nullptr)
  • from_stream (for month) πŸ‘
       template<typename _CharT, typename _Traits, typename _Alloc =
           allocator<_CharT>> basic_istream< _CharT, _Traits > & from_stream
           (basic_istream< _CharT, _Traits > &__is, const _CharT *__fmt, month
           &__m, basic_string< _CharT, _Traits, _Alloc > *__abbrev=nullptr,
           minutes *__offset=nullptr)
  • from_stream (for month_day) πŸ‘
       template<typename _CharT, typename _Traits, typename _Alloc =
           allocator<_CharT>> basic_istream< _CharT, _Traits > & from_stream
           (basic_istream< _CharT, _Traits > &__is, const _CharT *__fmt,
           month_day &__md, basic_string< _CharT, _Traits, _Alloc >
           *__abbrev=nullptr, minutes *__offset=nullptr)
  • from_stream (for sys_time) πŸ‘
       template<typename _CharT, typename _Traits, typename _Duration, typename
           _Alloc = allocator<_CharT>> basic_istream< _CharT, _Traits > &
           from_stream (basic_istream< _CharT, _Traits > &__is, const _CharT
           *__fmt, sys_time< _Duration > &__tp, basic_string< _CharT, _Traits,
           _Alloc > *__abbrev=nullptr, minutes *__offset=nullptr)
  • from_stream (for tai_time) πŸ‘
       template<typename _CharT, typename _Traits, typename _Duration, typename
           _Alloc = allocator<_CharT>> basic_istream< _CharT, _Traits > &
           from_stream (basic_istream< _CharT, _Traits > &__is, const _CharT
           *__fmt, tai_time< _Duration > &__tp, basic_string< _CharT, _Traits,
           _Alloc > *__abbrev=nullptr, minutes *__offset=nullptr)
  • from_stream (for utc_time) πŸ‘
       template<typename _CharT, typename _Traits, typename _Duration, typename
           _Alloc = allocator<_CharT>> basic_istream< _CharT, _Traits > &
           from_stream (basic_istream< _CharT, _Traits > &__is, const _CharT
           *__fmt, utc_time< _Duration > &__tp, basic_string< _CharT, _Traits,
           _Alloc > *__abbrev=nullptr, minutes *__offset=nullptr)
  • from_stream (for weekday) πŸ‘
       template<typename _CharT, typename _Traits, typename _Alloc =
           allocator<_CharT>> basic_istream< _CharT, _Traits > & from_stream
           (basic_istream< _CharT, _Traits > &__is, const _CharT *__fmt,
           weekday &__wd, basic_string< _CharT, _Traits, _Alloc >
           *__abbrev=nullptr, minutes *__offset=nullptr)
  • from_stream (for year) πŸ‘
       template<typename _CharT, typename _Traits, typename _Alloc =
           allocator<_CharT>> basic_istream< _CharT, _Traits > & from_stream
           (basic_istream< _CharT, _Traits > &__is, const _CharT *__fmt, year
           &__y, basic_string< _CharT, _Traits, _Alloc > *__abbrev=nullptr,
           minutes *__offset=nullptr)
  • from_stream (for year_month) πŸ‘
       template<typename _CharT, typename _Traits, typename _Alloc =
           allocator<_CharT>> basic_istream< _CharT, _Traits > & from_stream
           (basic_istream< _CharT, _Traits > &__is, const _CharT *__fmt,
           year_month &__ym, basic_string< _CharT, _Traits, _Alloc >
           *__abbrev=nullptr, minutes *__offset=nullptr)
  • from_stream (for year_month_day) πŸ‘
       template<typename _CharT, typename _Traits, typename _Alloc =
           allocator<_CharT>> basic_istream< _CharT, _Traits > & from_stream
           (basic_istream< _CharT, _Traits > &__is, const _CharT *__fmt,
           year_month_day &__ymd, basic_string< _CharT, _Traits, _Alloc >
           *__abbrev=nullptr, minutes *__offset=nullptr)
  • get_leap_second_info πŸ’œ
       template<typename _Duration> leap_second_info get_leap_second_info
           (const utc_time< _Duration > &__ut)
  • get_tzdb πŸ’œ
       const tzdb & get_tzdb ()
  • get_tzdb_list πŸ’œ
       tzdb_list & get_tzdb_list ()
  • is_am πŸŒ…
       constexpr bool is_am (const hours &__h) noexcept

True if a chrono::hours value represents a time before midday. morning vibes fr fr β˜€οΈ

  • is_pm πŸŒ‡
       constexpr bool is_pm (const hours &__h) noexcept

True if a chrono::hours value represents a time after midday. afternoon energy periodt πŸŒ™

  • local_time_format 🌿
       template<typename _Duration> __detail::__local_time_fmt< _Duration >
           local_time_format (local_time< _Duration > __time, const string
           *__abbrev=nullptr, const seconds *__offset_sec=nullptr)
  • locate_zone 🌿
       const time_zone * locate_zone (string_view __tz_name)
  • make12 πŸ•›
       constexpr hours make12 (const hours &__h) noexcept

Convert a 24-hour time into a 12-hour time. clock math slay πŸ’…

  • make24 πŸ•›
       constexpr hours make24 (const hours &__h, bool __is_pm) noexcept

Convert a 12-hour time and p.m. flag into a 24-hour time. the way it just works πŸ•°οΈ

  • operator<< (for day) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const day &__d)
  • operator<< (for file_time) πŸŽ€
       template<typename _CharT, typename _Traits, typename _Duration>
           basic_ostream< _CharT, _Traits > & operator<< (basic_ostream<
           _CharT, _Traits > &__os, const file_time< _Duration > &__t)
  • operator<< (for gps_time) πŸŽ€
       template<typename _CharT, typename _Traits, typename _Duration>
           basic_ostream< _CharT, _Traits > & operator<< (basic_ostream<
           _CharT, _Traits > &__os, const gps_time< _Duration > &__t)
  • operator<< (for hh_mm_ss) πŸŽ€
       template<typename _CharT, typename _Traits, typename _Duration>
           basic_ostream< _CharT, _Traits > & operator<< (basic_ostream<
           _CharT, _Traits > &__os, const hh_mm_ss< _Duration > &__hms)
  • operator<< (for local_info) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const local_info &__li)

Writes a local_info object to an ostream in an unspecified format. it's giving mysterious ✨

  • operator<< (for local_time) πŸŽ€
       template<typename _CharT, typename _Traits, typename _Duration>
           requires requires(const sys_time<_Duration>& __st) { __os << __st;
           }basic_ostream< _CharT, _Traits > & operator<< (basic_ostream<
           _CharT, _Traits > &__os, const local_time< _Duration > &__lt)"
  • operator<< (for month) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const month &__m)
  • operator<< (for month_day) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const month_day &__md)
  • operator<< (for month_day_last) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const month_day_last &__mdl)
  • operator<< (for month_weekday) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const month_weekday &__mwd)
  • operator<< (for month_weekday_last) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const month_weekday_last &__mwdl)
  • operator<< (for sys_days) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const sys_days &__dp)
  • operator<< (for sys_info) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const sys_info &__i)

Writes a sys_info object to an ostream in an unspecified format. also mysterious, no cap 🫢

  • operator<< (for sys_time) πŸŽ€
       template<typename _CharT, typename _Traits, typename _Duration>
           basic_ostream< _CharT, _Traits > & operator<< (basic_ostream<
           _CharT, _Traits > &__os, const sys_time< _Duration > &__tp)
  • operator<< (for tai_time) πŸŽ€
       template<typename _CharT, typename _Traits, typename _Duration>
           basic_ostream< _CharT, _Traits > & operator<< (basic_ostream<
           _CharT, _Traits > &__os, const tai_time< _Duration > &__t)
  • operator<< (for utc_time) πŸŽ€
       template<typename _CharT, typename _Traits, typename _Duration>
           basic_ostream< _CharT, _Traits > & operator<< (basic_ostream<
           _CharT, _Traits > &__os, const utc_time< _Duration > &__t)
  • operator<< (for weekday) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const weekday &__wd)
  • operator<< (for weekday_indexed) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const weekday_indexed &__wdi)
  • operator<< (for weekday_last) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
           const weekday_last &__wdl)
  • operator<< (continuing...) πŸŽ€
       template<typename _CharT, typename _Traits> basic_ostream< _CharT,
           _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,

Okay so, still deep in the SYNOPSIS, still thriving. πŸ’– This chunk is all the free functions and operators β€” the ones that make the chrono calendar types actually do stuff. Strap in bestie, we're going declaration by declaration and I'm not skipping a single one. ✨


πŸ’… first, the tail end of an operator<< (the year one)

This is literally just the last line of a declaration that started back in the previous part, so here it is, exactly as it landed:

    const year &__y)

Iconic. Moving on. 🫢


🌸 operator<< for every calendar type you own

Every one of these is the same energy: take a basic_ostream< _CharT, _Traits > &__os, take your date object, return the stream so you can chain. That's it. That's the whole vibe.

template<typename _CharT, typename _Traits> basic_ostream< _CharT,
    _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
    const year_month &__ym)
template<typename _CharT, typename _Traits> basic_ostream< _CharT,
    _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
    const year_month_day &__ymd)
template<typename _CharT, typename _Traits> basic_ostream< _CharT,
    _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
    const year_month_day_last &__ymdl)
template<typename _CharT, typename _Traits> basic_ostream< _CharT,
    _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
    const year_month_weekday &__ymwd)
template<typename _CharT, typename _Traits> basic_ostream< _CharT,
    _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
    const year_month_weekday_last &__ymwdl)

So like β€” year_month, year_month_day, year_month_day_last, year_month_weekday, year_month_weekday_last. All the calendar combos get to be printed. No cap. πŸ’œ

And then the two spicy ones β€” one for zoned_time (which carries its own _Duration and _TimeZonePtr), and one that takes a std::basic_ostream explicitly for a plain old duration:

template<typename _CharT, typename _Traits, typename _Duration, typename
    _TimeZonePtr> basic_ostream< _CharT, _Traits > & operator<<
    (basic_ostream< _CharT, _Traits > &__os, const zoned_time<
    _Duration, _TimeZonePtr > &__t)
template<typename _CharT, typename _Traits, typename _Rep, typename
    _Period> basic_ostream< _CharT, _Traits > & operator<<
    (std::basic_ostream< _CharT, _Traits > &__os, const duration< _Rep,
    _Period > &__d)

Note that the duration one is spelled with the full std::basic_ostream and the others aren't β€” that's just how it's written, don't come for me, I'm reporting the facts. πŸ“‹


✨ operator== for zoned_time, and it's cross-type

Two different zoned_times, each with their own _Dur and _TZPtr, and you can still ask if they're equal. Main character behaviour honestly.

template<typename _Dur1, typename _TZPtr1, typename _Dur2, typename
    _TZPtr2> bool operator== (const zoned_time< _Dur1, _TZPtr1 > &__x,
    const zoned_time< _Dur2, _TZPtr2 > &__y)

πŸŽ€ parse β€” the overload family reunion

Okay so this is the part where it's giving forty identical twins. 🌈 There's a whole swarm of parse overloads, and the way to read them is: does it take a const _CharT *__fmt or a const basic_string<...> &__fmt? Does it also give you back an __abbrev string? Does it also give you a minutes &__offset? That's it. Three little toggles, and boom, you've decoded the whole family. πŸ’…

The const _CharT *__fmt crew, plainest first:

template<typename _CharT, __detail::__parsable< _CharT > _Parsable> auto
    parse (const _CharT *__fmt, _Parsable &__tp)
template<typename _CharT, typename _Traits, typename _Alloc, typename
    _StrT = basic_string<_CharT, _Traits, _Alloc>, __detail::__parsable<
    _CharT, _Traits, _StrT > _Parsable> auto parse (const _CharT *__fmt,
    _Parsable &__tp, basic_string< _CharT, _Traits, _Alloc > &__abbrev)
template<typename _CharT, typename _Traits, typename _Alloc, typename
    _StrT = basic_string<_CharT, _Traits, _Alloc>, __detail::__parsable<
    _CharT, _Traits, _StrT, minutes > _Parsable> auto parse (const
    _CharT *__fmt, _Parsable &__tp, basic_string< _CharT, _Traits,
    _Alloc > &__abbrev, minutes &__offset)
template<typename _CharT, typename _Traits = char_traits<_CharT>,
    typename _StrT = basic_string<_CharT, _Traits>,
    __detail::__parsable< _CharT, _Traits, _StrT, minutes > _Parsable>
    auto parse (const _CharT *__fmt, _Parsable &__tp, minutes &__offset)

See what I mean? __abbrev? optional. __offset? optional. And heads up, the fourth one there is the one with typename _Traits = char_traits<_CharT> as a default β€” that's the one that stands out from the crowd. ⭐

Now the basic_string version, same family, different first argument:

template<typename _CharT, typename _Traits, typename _Alloc,
    __detail::__parsable< _CharT, _Traits > _Parsable> auto parse (const
    basic_string< _CharT, _Traits, _Alloc > &__fmt, _Parsable &__tp)
template<typename _CharT, typename _Traits, typename _Alloc, typename
    _StrT = basic_string<_CharT, _Traits, _Alloc>, __detail::__parsable<
    _CharT, _Traits, _StrT > _Parsable> auto parse (const basic_string<
    _CharT, _Traits, _Alloc > &__fmt, _Parsable &__tp, basic_string<
    _CharT, _Traits, _Alloc > &__abbrev)
template<typename _CharT, typename _Traits, typename _Alloc, typename
    _StrT = basic_string<_CharT, _Traits, _Alloc>, __detail::__parsable<
    _CharT, _Traits, _StrT, minutes > _Parsable> auto parse (const
    basic_string< _CharT, _Traits, _Alloc > &__fmt, _Parsable &__tp,
    basic_string< _CharT, _Traits, _Alloc > &__abbrev, minutes
    &__offset)
template<typename _CharT, typename _Traits, typename _Alloc, typename
    _StrT = basic_string<_CharT, _Traits>, __detail::__parsable< _CharT,
    _Traits, _StrT, minutes > _Parsable> auto parse (const basic_string<
    _CharT, _Traits, _Alloc > &__fmt, _Parsable &__tp, minutes
    &__offset)

Notice the _StrT default is spelled two different ways across these β€” basic_string<_CharT, _Traits, _Alloc> in most, and basic_string<_CharT, _Traits> in that last one. Yes, I noticed. Yes, I'm telling you. Copy it exactly or the compiler will simply not. 😭


πŸ¦‹ tzdb reload & remote version β€” two little free functions

const tzdb & reload_tzdb ()
string remote_version ()

reload_tzdb () hands you back a const tzdb &. remote_version () hands you back a plain string. Short, sweet, no template drama. πŸ“


πŸ”₯ round and time_point_cast β€” the enable_if girlies

These two are doing the whole SFINAE thing where they only even exist if your target type makes sense. Don't fight it, just read the constraints:

template<typename _ToDur, typename _Rep, typename _Period> constexpr
    enable_if_t< __and_< __is_duration< _ToDur >, __not_<
    treat_as_floating_point< typename _ToDur::rep > > >::value, _ToDur >
    round (const duration< _Rep, _Period > &__d)
template<typename _ToDur, typename _Clock, typename _Dur> constexpr
    enable_if_t< __is_duration_v< _ToDur > &&!treat_as_floating_point_v<
    typename _ToDur::rep >, time_point< _Clock, _ToDur > > round (const
    time_point< _Clock, _Dur > &__tp)
template<typename _ToDur, typename _Clock, typename _Dur> constexpr
    __enable_if_t< __is_duration< _ToDur >::value, time_point< _Clock,
    _ToDur > > time_point_cast (const time_point< _Clock, _Dur > &__t)

The duration round uses the old-school __and_ / __is_duration / __not_ / treat_as_floating_point combo. The time_point round uses the newer __is_duration_v / treat_as_floating_point_v variable-template spelling. And time_point_cast uses __enable_if_t with a ::value. Three different dialects of the same idea, all valid, all here. 🫢


πŸ‘‘ zoned_time deduction guides

This is the deduction guide section and honestly it's serving convenience. You get a default guide to zoned_time< seconds >, guides that sniff out the time zone representation from whatever _TimeZonePtrOrName you passed, guides that fold in a local_time< _Duration > or a sys_time< _Duration >, and a guide that takes another zoned_time and converts it. Several of them default choose to choose::earliest. ⭐

zoned_time () -> zoned_time< seconds >
template<typename _TimeZonePtrOrName> zoned_time (_TimeZonePtrOrName &&)
    -> zoned_time< seconds, __time_zone_representation<
    _TimeZonePtrOrName > >
template<typename _TimeZonePtrOrName, typename _Duration> zoned_time
    (_TimeZonePtrOrName &&, local_time< _Duration >,
    choose=choose::earliest) -> zoned_time< common_type_t< _Duration,
    seconds >, __time_zone_representation< _TimeZonePtrOrName > >
template<typename _TimeZonePtrOrName, typename _Duration> zoned_time
    (_TimeZonePtrOrName &&, sys_time< _Duration >) -> zoned_time<
    common_type_t< _Duration, seconds >, __time_zone_representation<
    _TimeZonePtrOrName > >
template<typename _Duration, typename _TimeZonePtrOrName, typename
    _TimeZonePtr2> zoned_time (_TimeZonePtrOrName &&, zoned_time<
    _Duration, _TimeZonePtr2 >, choose=choose::earliest) -> zoned_time<
    common_type_t< _Duration, seconds >, __time_zone_representation<
    _TimeZonePtrOrName > >
template<typename _Duration> zoned_time (sys_time< _Duration >) ->
    zoned_time< common_type_t< _Duration, seconds > >

Every single one that has a _Duration collapses it with common_type_t< _Duration, seconds >. That's the move. πŸ’… And yeah, the last one β€” zoned_time (sys_time< _Duration >) β€” doesn't have a choose parameter at all, and it doesn't take a zone name either, so don't @ me. πŸ™ˆ


🌈 time_point comparisons β€” the finale of this part

Last block, and it's the full comparison set for time_point. You've got the three-way operator<=> (constrained with three_way_comparable_with< _Dur1 > _Dur2, returning constexpr auto), plus the four classics: <, <=, >, >=. All constexpr, all taking const time_point< _Clock, _Dur1 > &__lhs and const time_point< _Clock, _Dur2 > &__rhs. Note that _Dur1 and _Dur2 are allowed to differ. Yes bestie, cross-duration comparison, we love to see it. πŸ’–

template<typename _Clock, typename _Dur1, three_way_comparable_with<
    _Dur1 > _Dur2> constexpr auto operator<=> (const time_point<
    _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 >
    &__rhs)
template<typename _Clock, typename _Dur1, typename _Dur2> constexpr
    bool operator< (const time_point< _Clock, _Dur1 > &__lhs, const
    time_point< _Clock, _Dur2 > &__rhs)
template<typename _Clock, typename _Dur1, typename _Dur2> constexpr
    bool operator<= (const time_point< _Clock, _Dur1 > &__lhs, const
    time_point< _Clock, _Dur2 > &__rhs)
template<typename _Clock, typename _Dur1, typename _Dur2> constexpr
    bool operator> (const time_point< _Clock, _Dur1 > &__lhs, const
    time_point< _Clock, _Dur2 > &__rhs)
template<typename _Clock, typename _Dur1, typename _Dur2> constexpr
    bool operator>= (const time_point< _Clock, _Dur1 > &__lhs, const
    time_point< _Clock, _Dur2 > &__rhs)

And that's where this chunk of the SYNOPSIS stops. ✨ The declarations keep going, so stay tuned, we're literally not done. 🧚

✨ Variables ✨

okay bestie, here's the whole vibe check of variables in std::chrono β€” every single one, no skips πŸ’–

  • constexpr month April
  • constexpr month August
  • constexpr month December
  • constexpr month February
  • constexpr weekday Friday
  • template<typename _Tp> constexpr bool is_clock_v
  • template<typename _Tp> constexpr bool is_clock_v< _Tp >
  • template<> constexpr bool is_clock_v< file_clock >
  • template<> constexpr bool is_clock_v< gps_clock >
  • template<> constexpr bool is_clock_v< steady_clock >
  • template<> constexpr bool is_clock_v< system_clock >
  • template<> constexpr bool is_clock_v< tai_clock >
  • template<> constexpr bool is_clock_v< utc_clock >
  • constexpr month January
  • constexpr month July
  • constexpr month June
  • constexpr last_spec last
  • constexpr month March
  • constexpr month May
  • constexpr weekday Monday
  • constexpr month November
  • constexpr month October
  • constexpr weekday Saturday
  • constexpr month September
  • constexpr weekday Sunday
  • constexpr weekday Thursday
  • template<typename _Rep> constexpr bool treat_as_floating_point_v
  • template<> constexpr bool treat_as_floating_point_v< double >
  • template<> constexpr bool treat_as_floating_point_v< float >
  • template<> constexpr bool treat_as_floating_point_v< int >
  • template<> constexpr bool treat_as_floating_point_v< long >
  • template<> constexpr bool treat_as_floating_point_v< long double >
  • template<> constexpr bool treat_as_floating_point_v< long long >
  • constexpr weekday Tuesday
  • constexpr weekday Wednesday

and here come the functions, all of them, no skips πŸ’…

template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator- (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)

bestie, this one gives you the difference between two durations πŸ’–

template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator+ (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)

and this one is the sum of two durations, slay ✨

template<typename _Rep1, typename _Rep2, typename _Period> constexpr duration< __common_rep_t< _Rep2, _Rep1 >, _Period > operator* (const _Rep1 &__s, const duration< _Rep2, _Period > &__d)
template<typename _Rep1, typename _Period, typename _Rep2> constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator/ (const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr common_type< _Rep1, _Rep2 >::type operator/ (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
template<typename _Rep1, typename _Period, typename _Rep2> constexpr duration< __common_rep_t< _Rep1, __disable_if_is_duration< _Rep2 > >, _Period > operator% (const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr common_type< duration< _Rep1, _Period1 >, duration< _Rep2, _Period2 > >::type operator% (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
template<typename _Rep1, typename _Period, typename _Rep2> constexpr duration< __common_rep_t< _Rep1, _Rep2 >, _Period > operator* (const duration< _Rep1, _Period > &__d, const _Rep2 &__s)
template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr bool operator< (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr auto operator<=> (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr bool operator<= (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr bool operator> (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr bool operator>= (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
template<typename _Rep1, typename _Period1, typename _Rep2, typename _Period2> constexpr bool operator== (const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
template<typename _Rep1, typename _Period1, typename _Clock, typename _Dur2> constexpr time_point< _Clock, typename common_type< duration< _Rep1, _Period1 >, _Dur2 >::type > operator+ (const duration< _Rep1, _Period1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs)

moves a time point forwards by the given duration, periodt πŸ•°οΈ

template<typename _Clock, typename _Dur1, typename _Rep2, typename _Period2> constexpr time_point< _Clock, typename common_type< _Dur1, duration< _Rep2, _Period2 > >::type > operator- (const time_point< _Clock, _Dur1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)

moves a time point backwards by the given duration, no cap πŸ’…

template<typename _Clock, typename _Dur1, typename _Dur2> constexpr common_type< _Dur1, _Dur2 >::type operator- (const time_point< _Clock, _Dur1 > &__lhs, const time_point< _Clock, _Dur2 > &__rhs)

gives you the difference between two time points (as a duration), iconic 🌈

template<typename _Clock, typename _Dur1, typename _Rep2, typename _Period2> constexpr time_point< _Clock, typename common_type< _Dur1, duration< _Rep2, _Period2 > >::type > operator+ (const time_point< _Clock, _Dur1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)

same energy: moves a time point forwards by the given duration, periodt πŸ’–

🌸 Detailed Description 🌸

ISO C++ 2011 namespace for date and time utilities. that's the whole glow-up, bestie ✨

πŸ‘‘ Author πŸ‘‘

Generated automatically by Doxygen for libstdc++ from the source code. no cap, the robots did this one πŸ€–


and that's a wrap! this page is from libstdc++ and it's the std::chrono(3) manual. the date isn't in this footer, but you know it's giving libstdc++ energy πŸ’…βœ¨

πŸ“¦ where this page comes from