150 lines
5.7 KiB
Markdown
150 lines
5.7 KiB
Markdown
[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<rep, period>; using time_point = chrono::time_point<tai_clock>; static constexpr bool is_steady = *unspecified*; static time_point now(); template<class Duration>static utc_time<common_type_t<Duration, seconds>> to_utc(const tai_time<Duration>&) noexcept; template<class Duration>static tai_time<common_type_t<Duration, seconds>> from_utc(const utc_time<Duration>&) 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<class Duration>
|
||
static utc_time<common_type_t<Duration, seconds>>
|
||
to_utc(const tai_time<Duration>& t) noexcept;
|
||
`
|
||
|
||
[2](#members-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3100)
|
||
|
||
*Returns*: utc_time<common_type_t<Duration, seconds>>{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<class Duration>
|
||
static tai_time<common_type_t<Duration, seconds>>
|
||
from_utc(const utc_time<Duration>& t) noexcept;
|
||
`
|
||
|
||
[3](#members-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3120)
|
||
|
||
*Returns*: tai_time<common_type_t<Duration, seconds>>{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<class charT, class traits, class Duration>
|
||
basic_ostream<charT, traits>&
|
||
operator<<(basic_ostream<charT, traits>& os, const tai_time<Duration>& 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*<charT>("{: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<tai_clock>(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<class charT, class traits, class Duration, class 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);
|
||
`
|
||
|
||
[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)
|