25 Time library [time]

25.7 Clocks [time.clock]

25.7.3 Class tai_­clock [time.clock.tai]

25.7.3.1 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;
  };
}
The clock tai_­clock measures seconds since 1958-01-01 00:00:00 and is offset 10s ahead of UTC at this date.
That is, 1958-01-01 00:00:00 TAI is equivalent to 1957-12-31 23:59:50 UTC.
Leap seconds are not inserted into TAI.
Therefore every time a leap second is inserted into UTC, UTC falls another second behind TAI.
For example by 2000-01-01 there had been 22 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).
tai_­clock is not a Cpp17TrivialClock unless the implementation can guarantee that tai_­clock​::​now() does not propagate an exception.
[Note
:
noexcept(from_­utc(utc_­clock​::​now())) is false.
end note
]

25.7.3.2 Member functions [time.clock.tai.members]

static time_point now();
Returns: from_­utc(utc_­clock​::​now()), or a more accurate value of tai_­time.
template<class Duration> static utc_time<common_type_t<Duration, seconds>> to_utc(const tai_time<Duration>& t) noexcept;
Returns:
utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 378691210s
[Note
:
378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s
end note
]
template<class Duration> static tai_time<common_type_t<Duration, seconds>> from_utc(const utc_time<Duration>& t) noexcept;
Returns:
tai_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 378691210s
[Note
:
378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s
end note
]

25.7.3.3 Non-member functions [time.clock.tai.nonmembers]

template<class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const tai_time<Duration>& t);
Effects: Calls to_­stream(os, fmt, t), where fmt is a string containing "%F %T" widened to charT.
Returns: os.
template<class charT, class traits, class Duration> basic_ostream<charT, traits>& to_stream(basic_ostream<charT, traits>& os, const charT* fmt, const tai_time<Duration>& tp);
Effects: Streams tp into os using the format specified by the NTCTS fmt.
fmt encoding follows the rules specified in [time.format].
If %Z is used, it will be replaced with "TAI".
If %z is used (or a modified variant of %z), an offset of 0min will be formatted.
The date and time formatted shall be equivalent to that formatted by a sys_­time initialized with:
sys_time<Duration>{tp.time_since_epoch()} -
  (sys_days{1970y/January/1} - sys_days{1958y/January/1})
Returns: os.
[Example
:
auto st = sys_days{2000y/January/1};
auto tt = clock_cast<tai_clock>(st);
cout << format("%F %T %Z == ", st) << format("%F %T %Z\n", tt);
Produces this output:
2000-01-01 00:00:00 UTC == 2000-01-01 00:00:32 TAI
end example
]
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);
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].
If the parse fails to decode a valid date, is.setstate(ios_­base​::​failbit) shall be called and tp shall not be modified.
If %Z is used and successfully parsed, that value will be assigned to *abbrev if abbrev is non-null.
If %z (or a modified variant) is used and successfully parsed, that value will be assigned to *offset if offset is non-null.
Additionally, the parsed offset will be subtracted from the successfully parsed timestamp prior to assigning that difference to tp.
Returns: is.