std::chrono(3cxx)
π°οΈ NAME
Okay bestie, this is the std::chrono(3cxx) page β manual section 3cxx, in the building, serving looks. And what is it? Itβs the ISO C++ 2011 namespace for date and time utilities. Thatβs the whole NAME vibe: std::chrono is the ISO C++ 2011 namespace for date and time utilities. Periodt. π
β¨ SYNOPSIS β¨
This is the cast list, and every single name below matters. No skipping, no βclose enough,β no cap. π
Classes
class durationβchrono::durationrepresents a distance between two points in time.struct duration_valuesβ the description here is literallyduration_values. Minimalist. Mysterious. Iconic.class gps_clockβ no extra description on this page, just the name doing its main character thing.class hh_mm_ssβ same energy: name only, no little blurb attached.struct steady_clockβMonotonic clock.struct system_clockβSystem clock.class tai_clockβ no extra description here either, just the class name.class time_pointβchrono::time_pointrepresents a point in time as measured by a clock.struct treat_as_floating_pointβ no description on the page, just the name.class tzdb_listβ again, name only. The mystery is the branding. π¦class utc_clockβ name only, no description attached.
Typedefs
using days = duration< int64_t, ratio< 86400 > >β blurb:days.using file_clock = ::std::filesystem::__file_clockβ no extra description, just this exact alias.template<typename _Duration > using file_time = time_point< file_clock, _Duration >β no extra description attached.using gps_seconds = gps_time< seconds >β no extra description, just the alias.template<typename _Duration > using gps_time = time_point< gps_clock, _Duration >β no blurb here.using high_resolution_clock = system_clockβHighest-resolution clock.using hours = duration< int64_t, ratio< 3600 > >β blurb:hours.using local_days = local_time< days >β no extra description.using local_seconds = local_time< seconds >β no extra description.template<typename _Duration > using local_time = time_point< local_t, _Duration >β no extra description.using microseconds = duration< int64_t, micro >β blurb:microseconds.using milliseconds = duration< int64_t, milli >β blurb:milliseconds.using minutes = duration< int64_t, ratio< 60 > >β blurb:minutes.using months = duration< int64_t, ratio< 2629746 > >β blurb:months.using nanoseconds = duration< int64_t, nano >β blurb:nanoseconds.using seconds = duration< int64_t >β blurb:seconds.using sys_days = sys_time< days >β no extra description.using sys_seconds = sys_time< seconds >β no extra description.template<typename _Duration > using sys_time = time_point< system_clock, _Duration >β no extra description.using tai_seconds = tai_time< seconds >β no extra description.template<typename _Duration > using tai_time = time_point< tai_clock, _Duration >β no extra description.using utc_seconds = utc_time< seconds >β no extra description.template<typename _Duration > using utc_time = time_point< utc_clock, _Duration >β no extra description.using weeks = duration< int64_t, ratio< 604800 > >β blurb:weeks.using years = duration< int64_t, ratio< 31556952 > >β blurb:years.using zoned_seconds = zoned_time< seconds >β no extra description.
Enumerations
enum class choose { earliest, latest }β thatβs the enum, and those are the two enumerators:earliestandlatest. No extra blurb on this page. π
π οΈ Functions
okay bestie, this is the whole squad π
β every free function in the <chrono> posse, with the signatures copied exactly so you can paste them and slay. And yes, almost every from_stream girlie comes with the same two defaulted trailing args (__abbrev=nullptr and __offset=nullptr) β we love a consistent aesthetic π
__throw_bad_local_timeβ lowkey the thrower-helper: it'svoid, and it takes alocal_time< _Duration >(that's__tp) plus alocal_info(that's__i). Signature, verbatim:template<typename _Duration > void __throw_bad_local_time (const local_time< _Duration > &__tp, const local_info &__i)abs(thedurationone) β theabsoverload for aduration< _Rep, _Period >,constexpr, and gated so it only shows up whennumeric_limits< _Rep >::is_signedis true π₯template<typename _Rep , typename _Period > constexpr enable_if_t< numeric_limits< _Rep >::is_signed, duration< _Rep, _Period > > abs (duration< _Rep, _Period > __d)ceil(thedurationone) βceilfor aduration, handing you back a_ToDur,constexpr, gated by__enable_if_is_duration< _ToDur >β¨template<typename _ToDur , typename _Rep , typename _Period > constexpr __enable_if_is_duration< _ToDur > ceil (const duration< _Rep, _Period > &__d)ceil(thetime_pointone) β sameceilenergy but for atime_point< _Clock, _Dur >, and you get atime_point< _Clock, _ToDur >back, gated by__is_duration_v< _ToDur >π«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β Convert a time point to a different clock. Iconic behaviour, and look at thatrequiresclause β it's a five-way serve of__detail::__clock_convs<_DestClock, _SourceClock, _Duration>,__detail::__clock_convs_sys<...>,__detail::__clock_convs_utc<...>,__detail::__clock_convs_sys_utc<...>, and__detail::__clock_convs_utc_sys<...>. No cap, she's picky: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)current_zoneβ zero args, oneconst time_zone *coming your way π¦const time_zone * current_zone ()duration_castβ the classic β¨constexpr, takesconst duration< _Rep, _Period > &__d, gives back_ToDur, gated by__enable_if_is_duration< _ToDur >:template<typename _ToDur , typename _Rep , typename _Period > constexpr __enable_if_is_duration< _ToDur > duration_cast (const duration< _Rep, _Period > &__d)floor(thedurationone) βfloorfor aduration,constexpr, same__enable_if_is_duration< _ToDur >gate, returns_ToDurπΈtemplate<typename _ToDur , typename _Rep , typename _Period > constexpr __enable_if_is_duration< _ToDur > floor (const duration< _Rep, _Period > &__d)floor(thetime_pointone) βfloorfor atime_point< _Clock, _Dur >βtime_point< _Clock, _ToDur >,constexpr, gated by__is_duration_v< _ToDur >π«Ά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)
π the from_stream girlies (there are 14 of them, bestie)
Every single one is a basic_istream< _CharT, _Traits > & and ends with the same two defaulted args: basic_string< _CharT, _Traits, _Alloc > *__abbrev=nullptr, minutes *__offset=nullptr. The _Alloc default is always = allocator<_CharT>. Obsessed with the consistency fr fr π
from_streamβdaytemplate<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βduration(this one also templates on_Repand_Period)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βfile_timetemplate<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βgps_timetemplate<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βlocal_timetemplate<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βmonthtemplate<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βmonth_daytemplate<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βsys_timetemplate<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βtai_timetemplate<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βutc_timetemplate<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βweekdaytemplate<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βyeartemplate<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βyear_monthtemplate<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βyear_month_daytemplate<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β takes aconst utc_time< _Duration > &__utand hands you aleap_second_infoπtemplate<typename _Duration > leap_second_info get_leap_second_info (const utc_time< _Duration > &__ut)get_tzdbβ no args, returns aconst tzdb &βconst tzdb & get_tzdb ()get_tzdb_listβ no args, returns atzdb_list &πtzdb_list & get_tzdb_list ()is_amβconstexpr bool, takesconst hours &__h, and it'snoexcept(respected) β¨constexpr bool is_am (const hours &__h) noexceptis_pmβ same deal,constexpr bool,noexcept,const hours &__hπconstexpr bool is_pm (const hours &__h) noexceptlocal_time_formatβ templates on_Duration, returns__detail::__local_time_fmt< _Duration >, takeslocal_time< _Duration > __timeplus the defaultedconst string *__abbrev=nullptrandconst seconds *__offset_sec=nullptrπ«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β takesstring_view __tz_name, gives aconst time_zone *π¦const time_zone * locate_zone (string_view __tz_name)make12βconstexpr hours,const hours &__h,noexceptπΈconstexpr hours make12 (const hours &__h) noexceptmake24βconstexpr hours, takesconst hours &__hand abool __is_pm,noexceptπΊconstexpr hours make24 (const hours &__h, bool __is_pm) noexcept
π
the operator<< era
operator<<βdaytemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const day &__d)operator<<βfile_timetemplate<typename _CharT , typename _Traits , typename _Duration > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const file_time< _Duration > &__t)operator<<βgps_timetemplate<typename _CharT , typename _Traits , typename _Duration > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const gps_time< _Duration > &__t)operator<<βhh_mm_sstemplate<typename _CharT , typename _Traits , typename _Duration > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const hh_mm_ss< _Duration > &__hms)operator<<βlocal_infoβ Writes alocal_infoobject to anostreamin an unspecified format. Unspecified, bestie β so don't go building a parser on the exact shape πtemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const local_info &__li)operator<<βlocal_timetemplate<typename _CharT , typename _Traits , typename _Duration > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const local_time< _Duration > &__lt)operator<<βmonthtemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const month &__m)operator<<βmonth_daytemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const month_day &__md)operator<<βmonth_day_lasttemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const month_day_last &__mdl)operator<<βmonth_weekdaytemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const month_weekday &__mwd)operator<<βmonth_weekday_lasttemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const month_weekday_last &__mwdl)operator<<βsys_daystemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const sys_days &__dp)operator<<βsys_infoβ Writes asys_infoobject to anostreamin an unspecified format. Again: unspecified π«Άtemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const sys_info &__i)operator<<βsys_timeβ this one's got arequiresclause:(!treat_as_floating_point_v<typename _Duration::rep>) && ratio_less_v<typename _Duration::period, days::period>π₯template<typename _CharT , typename _Traits , typename _Duration >requires (!treat_as_floating_point_v<typename _Duration::rep>) && ratio_less_v<typename _Duration::period, days::period>basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const sys_time< _Duration > &__tp)operator<<βtai_timetemplate<typename _CharT , typename _Traits , typename _Duration > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const tai_time< _Duration > &__t)operator<<βutc_timetemplate<typename _CharT , typename _Traits , typename _Duration > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const utc_time< _Duration > &__t)operator<<βweekdaytemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const weekday &__wd)operator<<βweekday_indexedtemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const weekday_indexed &__wdi)operator<<βweekday_lasttemplate<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os, const weekday_last &__wdl)operator<<β the next overload β and it keeps going, no cap π the signature rolls straight out of this chunk:template<typename _CharT , typename _Traits > basic_ostream< _CharT,
πΈ the operator<< girlies β printing every chrono type you own
okay so every single calendar type and duration type has its own stream operator, and they're all templates because of course they are. bestie, these are the ones that make std::cout << work without you crying:
template<typename _CharT , typename _Traits > basic_ostream< _CharT,
_Traits > & operator<< (basic_ostream< _CharT, _Traits > &__os,
const year &__y)
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)
and obviously the timezone one gets its own extra template params, because zoned_time can never just be simple π
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)
and the duration one is fully qualified with std:: on the stream, which is giving "i was written by a different maintainer" energy but we respect it π«Ά
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)
π
zoned_time equality (yes, == specifically)
one (1) comparison operator lives here and it's the equality one. no <, no <=>, just vibes and bool:
template<typename _Dur1 , typename _TZPtr1 , typename _Dur2 , typename
_TZPtr2 > bool operator== (const zoned_time< _Dur1, _TZPtr1 > &__x,
const zoned_time< _Dur2, _TZPtr2 > &__y)
π¦ the parse overloads β reading strings back into chrono
this whole flock of overloads exists so you can go from text π chrono objects, and there are so many of them because C++ said "what if every parameter got its own version". _Parsable is constrained by __detail::__parsable, and some of these hand you back an __abbrev string and/or a minutes& __offset. slay.
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)
this next one is the offset-only, pointer-flavored, no _Alloc variant β note the _StrT default here is just basic_string< _CharT, _Traits>, and the _Traits default is char_traits<_CharT>. copy it exactly, bestie, don't get creative π
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)
and now the exact same four flavors but taking basic_string for __fmt instead of const _CharT *, because consistency is a love language:
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)
π tzdb glow-ups + rounding + casting
three(3) little legendary functions. reload_tzdb hands you back a const tzdb &, remote_version gives you a string, and then round/time_point_cast do the actual glow-up math β¨
const tzdb & reload_tzdb ()
string remote_version ()
round for a duration β note the enable_if_t gate: _ToDur has to be a duration, and its rep must not be treat_as_floating_point. so floating-point reps are literally not invited π«
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)
same energy for a time_point version, this one gated with __is_duration_v and !treat_as_floating_point_v:
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)
and time_point_cast β classic, __enable_if_t on __is_duration< _ToDur >::value, returns the recast time_point:
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)
π zoned_time deduction guides
deduction guides my beloved π they let you write zoned_time without spelling out the template args like a Victorian.
the plain one drops you into seconds:
zoned_time () -> zoned_time< seconds >
timezone pointer or name, still seconds:
template<typename _TimeZonePtrOrName > zoned_time (_TimeZonePtrOrName
&&) -> zoned_time< seconds, __time_zone_representation<
_TimeZonePtrOrName > >
with a local_time, and note the choose=choose::earliest default sitting right there in the guide:
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 > >
with a sys_time β no choose here, just vibes:
template<typename _TimeZonePtrOrName , typename _Duration > zoned_time
(_TimeZonePtrOrName &&, sys_time< _Duration >) -> zoned_time<
common_type_t< _Duration, seconds >, __time_zone_representation<
_TimeZonePtrOrName > >
copy-construct-ish from another zoned_time, choose=choose::earliest again:
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 > >
and one lone sys_time guide, no timezone param at all:
template<typename _Duration > zoned_time (sys_time< _Duration >) ->
zoned_time< common_type_t< _Duration, seconds > >
π₯ duration math β + - * / %
the actual arithmetic, and it's all constexpr because of course it is. the subtraction has an official description, and i quote:
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)
The difference between two durations.
scalar-times-duration goes _Rep1 first (const _Rep1 &__s), and uses __common_rep_t both ways:
template<typename _Rep1 , typename _Rep2 , typename _Period >
constexpr duration< __common_rep_t< _Rep2, _Rep1 >, _Period >
operator* (const _Rep1 &__s, const duration< _Rep2, _Period >
&__d)
duration-divided-by-scalar, with that __disable_if_is_duration< _Rep2 > guard so you can't accidentally divide by a duration here:
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)
duration Γ· duration, and this one returns common_type< _Rep1, _Rep2 >::type β like, a plain number, not a duration. iconique:
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)
modulo, same guard as the scalar divide:
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)
and duration % duration, back to a duration result this time:
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)
π duration comparisons
five(5) of these bad boys. <, <=, >, >= are all plain constexpr bool, and the <=> is the special one β it's requires three_way_comparable<common_type_t<_Rep1, _Rep2>>, so if your reps aren't three-way comparable it simply does not exist for you. no cap.
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 >
requires three_way_comparable<common_type_t<_Rep1,
_Rep2>>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)
π time_point math β add a duration, subtract a duration, subtract a time_point
this is the "moving through time" triad and the descriptions are genuinely so clean:
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)
Adjust a time point forwards by the given duration.
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)
Adjust a time point backwards by the given duration.
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)
The difference between two time points (as a duration)
β time_point comparisons
and the comparison set for time_points, where <=> is constrained by three_way_comparable_with< _Dur1 > _Dur2 (note the > _Dur2> spacing, keep it exactly like that bestie π«Ά):
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)
π VARIABLES π
okay bestie, this is the cast list. Every variable, every specialization, every little constexpr moment β all here, in the exact order the page gave them. No skips, no edits, no βclose enoughβ energy. π
__is_time_point_for_vβ base template declaration:template<typename _Tp , typename _Clock > constexpr bool __is_time_point_for_v. Sheβs the generic trait girlie β¨__is_time_point_for_v< time_point< _Clock, _Duration >, _Clock >β the partial specialization:template<typename _Clock , typename _Duration > constexpr bool __is_time_point_for_v< time_point< _Clock, _Duration >, _Clock >. Itβs givingtime_pointexcellence π«ΆAprilβconstexpr month April. Month constant for April, no cap πΈAugustβconstexpr month August. Month constant for August βοΈDecemberβconstexpr month December. Month constant for December πFebruaryβconstexpr month February. Month constant for February πFridayβconstexpr weekday Friday. Weekday constant for Friday, and yes she has main character energy πis_clock_vβ base template:template<typename _Tp , typename = void> constexpr bool is_clock_v. Note the exacttypename = voidspacing, preserved for the culture β¨is_clock_v< file_clock >β specialization:template<> constexpr bool is_clock_v< file_clock >. Clock trait moment forfile_clockπ°οΈis_clock_v< gps_clock >β specialization:template<> constexpr bool is_clock_v< gps_clock >. Clock trait moment forgps_clockπ°οΈis_clock_v< steady_clock >β specialization:template<> constexpr bool is_clock_v< steady_clock >. Clock trait moment forsteady_clockβ³is_clock_v< system_clock >β specialization:template<> constexpr bool is_clock_v< system_clock >. Clock trait moment forsystem_clockπ₯οΈis_clock_v< tai_clock >β specialization:template<> constexpr bool is_clock_v< tai_clock >. Clock trait moment fortai_clockπis_clock_v< utc_clock >β specialization:template<> constexpr bool is_clock_v< utc_clock >. Clock trait moment forutc_clockπJanuaryβconstexpr month January. Month constant for January βοΈJulyβconstexpr month July. Month constant for July πJuneβconstexpr month June. Month constant for June πlastβconstexpr last_spec last. Thelast_specmarker literally namedlast, and it knows it πMarchβconstexpr month March. Month constant for March π·Mayβconstexpr month May. Month constant for May πΌMondayβconstexpr weekday Monday. Weekday constant for Monday, lowkey iconic in her own way π©΅Novemberβconstexpr month November. Month constant for November πOctoberβconstexpr month October. Month constant for October πSaturdayβconstexpr weekday Saturday. Weekday constant for Saturday, the weekend queen πSeptemberβconstexpr month September. Month constant for September πSundayβconstexpr weekday Sunday. Weekday constant for Sunday, soft-girl rest-day energy πΈThursdayβconstexpr weekday Thursday. Weekday constant for Thursday, almost-Friday royalty πtreat_as_floating_point_vβ base template:template<typename _Rep > constexpr bool treat_as_floating_point_v. Trait declaration, serving exactly as written β¨treat_as_floating_point_v< double >β specialization:template<> constexpr bool treat_as_floating_point_v< double >. Thedoublemoment π«treat_as_floating_point_v< float >β specialization:template<> constexpr bool treat_as_floating_point_v< float >. Thefloatmoment π«§treat_as_floating_point_v< int >β specialization:template<> constexpr bool treat_as_floating_point_v< int >. Theintmoment π’treat_as_floating_point_v< long >β specialization:template<> constexpr bool treat_as_floating_point_v< long >. Thelongmoment πtreat_as_floating_point_v< long double >β specialization:template<> constexpr bool treat_as_floating_point_v< long double >. Thelong doublemoment πtreat_as_floating_point_v< long long >β specialization:template<> constexpr bool treat_as_floating_point_v< long long >. Thelong longmoment πTuesdayβconstexpr weekday Tuesday. Weekday constant for Tuesday, underrated but valid π¦Wednesdayβconstexpr weekday Wednesday. Weekday constant for Wednesday, the midweek main character π
π°οΈ DETAILED DESCRIPTION π°οΈ
The official sentence is: ISO C++ 2011 namespace for date and time utilities. Thatβs the whole vibe. std::chrono is the ISO C++ 2011 namespace for date and time utilities, and it said what it said. Periodt. π¦β¨
π AUTHOR π
Generated automatically by Doxygen for libstdc++ from the source code. So yes, the author line is the Doxygen auto-gen flex. Respect the pipeline, bestie π«Ά
okay thatβs the page, and the footer vibe is: source/version libstdc++, page std::chrono(3cxx), and the date isnβt visible in this chunk β so Iβm not making one up. Consider this your cute sign-off: ππβ¨
π¦ where this page comes from
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms