[time.clock.cast] # 30 Time library [[time]](./#time) ## 30.7 Clocks [[time.clock]](time.clock#cast) ### 30.7.10 time_point conversions [time.clock.cast] #### [30.7.10.1](#time.clock.conv) Class template clock_time_conversion [[time.clock.conv]](time.clock.conv) namespace std::chrono {templatestruct clock_time_conversion {};} [1](#time.clock.conv-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3583) clock_time_conversion serves as a trait which can be used to specify how to convert a source time_point of typetime_point to a destination time_point of typetime_point via a specialization:clock_time_conversion[.](#time.clock.conv-1.sentence-1) A specialization of clock_time_conversion shall provide a const-qualified operator() that takes a parameter of type time_point and returns a time_point representing an equivalent point in time[.](#time.clock.conv-1.sentence-2) OtherDuration is a chrono​::​duration whose specialization is computed from the input Duration in a manner which can vary for each clock_time_conversion specialization[.](#time.clock.conv-1.sentence-3) A program may specialize clock_time_conversion if at least one of the template parameters is a user-defined clock type[.](#time.clock.conv-1.sentence-4) [2](#time.clock.conv-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3603) Several specializations are provided by the implementation, as described in[[time.clock.cast.id]](#id "30.7.10.2 Identity conversions"),[[time.clock.cast.sys.utc]](#sys.utc "30.7.10.3 Conversions between system_­clock and utc_­clock"),[[time.clock.cast.sys]](#sys "30.7.10.4 Conversions between system_­clock and other clocks"), and[[time.clock.cast.utc]](#utc "30.7.10.5 Conversions between utc_­clock and other clocks")[.](#time.clock.conv-2.sentence-1) #### [30.7.10.2](#id) Identity conversions [[time.clock.cast.id]](time.clock.cast.id) templatestruct clock_time_conversion {template time_pointoperator()(const time_point& t) const;}; [🔗](#lib:operator(),clock_time_conversion) `template time_point operator()(const time_point& t) const; ` [1](#id-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3630) *Returns*: t[.](#id-1.sentence-1) template<>struct clock_time_conversion {template sys_timeoperator()(const sys_time& t) const;}; [🔗](#lib:operator(),clock_time_conversion_) `template sys_time operator()(const sys_time& t) const; ` [2](#id-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3652) *Returns*: t[.](#id-2.sentence-1) template<>struct clock_time_conversion {template utc_timeoperator()(const utc_time& t) const;}; [🔗](#lib:operator(),clock_time_conversion__) `template utc_time operator()(const utc_time& t) const; ` [3](#id-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3674) *Returns*: t[.](#id-3.sentence-1) #### [30.7.10.3](#sys.utc) Conversions between system_clock and utc_clock [[time.clock.cast.sys.utc]](time.clock.cast.sys.utc) template<>struct clock_time_conversion {template utc_time>operator()(const sys_time& t) const;}; [🔗](#lib:operator(),clock_time_conversion___) `template utc_time> operator()(const sys_time& t) const; ` [1](#sys.utc-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3698) *Returns*: utc_clock​::​from_sys(t)[.](#sys.utc-1.sentence-1) template<>struct clock_time_conversion {template sys_time>operator()(const utc_time& t) const;}; [🔗](#lib:operator(),clock_time_conversion____) `template sys_time> operator()(const utc_time& t) const; ` [2](#sys.utc-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3720) *Returns*: utc_clock​::​to_sys(t)[.](#sys.utc-2.sentence-1) #### [30.7.10.4](#sys) Conversions between system_clock and other clocks [[time.clock.cast.sys]](time.clock.cast.sys) templatestruct clock_time_conversion {templateauto operator()(const time_point& t) const-> decltype(SourceClock::to_sys(t));}; [🔗](#lib:operator(),clock_time_conversion_____) `template auto operator()(const time_point& t) const -> decltype(SourceClock::to_sys(t)); ` [1](#sys-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3744) *Constraints*: SourceClock​::​to_sys(t) is well-formed[.](#sys-1.sentence-1) [2](#sys-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3748) *Mandates*: SourceClock​::​to_sys(t) returns a sys_time for some type Duration2 ([[time.point.general]](time.point.general "30.6.1 General"))[.](#sys-2.sentence-1) [3](#sys-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3753) *Returns*: SourceClock​::​to_sys(t)[.](#sys-3.sentence-1) templatestruct clock_time_conversion {templateauto operator()(const sys_time& t) const-> decltype(DestClock::from_sys(t));}; [🔗](#lib:operator(),clock_time_conversion______) `template auto operator()(const sys_time& t) const -> decltype(DestClock::from_sys(t)); ` [4](#sys-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3775) *Constraints*: DestClock​::​from_sys(t) is well-formed[.](#sys-4.sentence-1) [5](#sys-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3779) *Mandates*: DestClock​::​from_sys(t) returns a time_point for some type Duration2 ([[time.point.general]](time.point.general "30.6.1 General"))[.](#sys-5.sentence-1) [6](#sys-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3784) *Returns*: DestClock​::​from_sys(t)[.](#sys-6.sentence-1) #### [30.7.10.5](#utc) Conversions between utc_clock and other clocks [[time.clock.cast.utc]](time.clock.cast.utc) templatestruct clock_time_conversion {templateauto operator()(const time_point& t) const-> decltype(SourceClock::to_utc(t));}; [🔗](#lib:operator(),clock_time_conversion_______) `template auto operator()(const time_point& t) const -> decltype(SourceClock::to_utc(t)); ` [1](#utc-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3808) *Constraints*: SourceClock​::​to_utc(t) is well-formed[.](#utc-1.sentence-1) [2](#utc-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3812) *Mandates*: SourceClock​::​to_utc(t) returns a utc_time for some type Duration2 ([[time.point.general]](time.point.general "30.6.1 General"))[.](#utc-2.sentence-1) [3](#utc-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3817) *Returns*: SourceClock​::​to_utc(t)[.](#utc-3.sentence-1) templatestruct clock_time_conversion {templateauto operator()(const utc_time& t) const-> decltype(DestClock::from_utc(t));}; [🔗](#lib:operator(),clock_time_conversion________) `template auto operator()(const utc_time& t) const -> decltype(DestClock::from_utc(t)); ` [4](#utc-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3839) *Constraints*: DestClock​::​from_utc(t) is well-formed[.](#utc-4.sentence-1) [5](#utc-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3843) *Mandates*: DestClock​::​from_utc(t) returns a time_point for some type Duration2 ([[time.point.general]](time.point.general "30.6.1 General"))[.](#utc-5.sentence-1) [6](#utc-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3848) *Returns*: DestClock​::​from_utc(t)[.](#utc-6.sentence-1) #### [30.7.10.6](#fn) Function template clock_cast [[time.clock.cast.fn]](time.clock.cast.fn) [🔗](#lib:clock_cast) `template auto clock_cast(const time_point& t); ` [1](#fn-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3862) *Constraints*: At least one of the following clock time conversion expressions is well-formed: - [(1.1)](#fn-1.1) clock_time_conversion{}(t) - [(1.2)](#fn-1.2) clock_time_conversion{}( clock_time_conversion{}(t)) - [(1.3)](#fn-1.3) clock_time_conversion{}( clock_time_conversion{}(t)) - [(1.4)](#fn-1.4) clock_time_conversion{}( clock_time_conversion{}( clock_time_conversion{}(t))) - [(1.5)](#fn-1.5) clock_time_conversion{}( clock_time_conversion{}( clock_time_conversion{}(t))) A clock time conversion expression is considered better than another clock time conversion expression if it involves feweroperator() calls on clock_time_conversion specializations[.](#fn-1.sentence-2) [2](#fn-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3904) *Mandates*: Among the well-formed clock time conversion expressions from the above list, there is a unique best expression[.](#fn-2.sentence-1) [3](#fn-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3909) *Returns*: The best well-formed clock time conversion expression in the above list[.](#fn-3.sentence-1)