[time.clock.tai] # 30 Time library [[time]](./#time) ## 30.7 Clocks [[time.clock]](time.clock#tai) ### 30.7.4 Class tai_clock [time.clock.tai] #### [30.7.4.1](#overview) Overview [[time.clock.tai.overview]](time.clock.tai.overview) namespace std::chrono {class tai_clock {public:using rep = *a signed arithmetic type*; using period = ratio<*unspecified*, *unspecified*>; using duration = chrono::duration; using time_point = chrono::time_point; static constexpr bool is_steady = *unspecified*; static time_point now(); templatestatic utc_time> to_utc(const tai_time&) noexcept; templatestatic tai_time> from_utc(const utc_time&) noexcept; };} [1](#overview-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3059) The clock tai_clock measures seconds since 1958-01-01 00:00:00 and is offset 10s ahead of UTC at this date[.](#overview-1.sentence-1) That is, 1958-01-01 00:00:00 TAI is equivalent to 1957-12-31 23:59:50 UTC[.](#overview-1.sentence-2) Leap seconds are not inserted into TAI[.](#overview-1.sentence-3) Therefore every time a leap second is inserted into UTC, UTC shifts another second with respect to TAI[.](#overview-1.sentence-4) For example by 2000-01-01 there had been 22 positive and 0 negative leap seconds inserted so 2000-01-01 00:00:00 UTC is equivalent to 2000-01-01 00:00:32 TAI (22s plus the initial 10s offset)[.](#overview-1.sentence-5) [2](#overview-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3071) tai_clock is not a [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3 Cpp17Clock requirements [time.clock.req]") unless the implementation can guarantee that tai_clock​::​now() does not propagate an exception[.](#overview-2.sentence-1) [*Note [1](#overview-note-1)*: noexcept(from_utc(utc_clock​::​now())) is false[.](#overview-2.sentence-2) — *end note*] #### [30.7.4.2](#members) Member functions [[time.clock.tai.members]](time.clock.tai.members) [🔗](#lib:now,tai_clock) `static time_point now(); ` [1](#members-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3087) *Returns*: from_utc(utc_clock​::​now()), or a more accurate value of tai_time[.](#members-1.sentence-1) [🔗](#lib:to_utc,tai_clock) `template static utc_time> to_utc(const tai_time& t) noexcept; ` [2](#members-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3100) *Returns*: utc_time>{t.time_since_epoch()} - 378691210s [*Note [1](#members-note-1)*: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s — *end note*] [🔗](#lib:from_utc,tai_clock) `template static tai_time> from_utc(const utc_time& t) noexcept; ` [3](#members-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3120) *Returns*: tai_time>{t.time_since_epoch()} + 378691210s [*Note [2](#members-note-2)*: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s — *end note*] #### [30.7.4.3](#nonmembers) Non-member functions [[time.clock.tai.nonmembers]](time.clock.tai.nonmembers) [🔗](#lib:operator%3c%3c,tai_time) `template basic_ostream& operator<<(basic_ostream& os, const tai_time& t); ` [1](#nonmembers-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3142) *Effects*: Equivalent to:return os << format(os.getloc(), *STATICALLY-WIDEN*("{:L%F %T}"), t); [2](#nonmembers-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3149) [*Example [1](#nonmembers-example-1)*: auto st = sys_days{2000y/January/1};auto tt = clock_cast(st); cout << format("{0:%F %T %Z} == {1:%F %T %Z}\n", st, tt); Produces this output: ``` 2000-01-01 00:00:00 UTC == 2000-01-01 00:00:32 TAI ``` — *end example*] [🔗](#lib:from_stream,tai_time) `template> basic_istream& from_stream(basic_istream& is, const charT* fmt, tai_time& tp, basic_string* abbrev = nullptr, minutes* offset = nullptr); ` [3](#nonmembers-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3175) *Effects*: Attempts to parse the input stream is into the tai_time tp using the format flags given in the NTCTS fmt as specified in [[time.parse]](time.parse "30.13 Parsing")[.](#nonmembers-3.sentence-1) If the parse fails to decode a valid date,is.setstate(ios_base​::​failbit) is called andtp is not modified[.](#nonmembers-3.sentence-2) If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null[.](#nonmembers-3.sentence-3) If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null[.](#nonmembers-3.sentence-4) Additionally, the parsed offset will be subtracted from the successfully parsed timestamp prior to assigning that difference to tp[.](#nonmembers-3.sentence-5) [4](#nonmembers-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3191) *Returns*: is[.](#nonmembers-4.sentence-1)