Files
2025-10-25 03:02:53 +03:00

5.6 KiB
Raw Permalink Blame History

[time.clock.gps]

30 Time library [time]

30.7 Clocks [time.clock]

30.7.5 Class gps_clock [time.clock.gps]

30.7.5.1 Overview [time.clock.gps.overview]

namespace std::chrono {class gps_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<gps_clock>; static constexpr bool is_steady = unspecified; static time_point now(); templatestatic utc_time<common_type_t<Duration, seconds>> to_utc(const gps_time&) noexcept; templatestatic gps_time<common_type_t<Duration, seconds>> from_utc(const utc_time&) noexcept; };}

1

#

The clock gps_clock measures seconds since the first Sunday of January, 1980 00:00:00 UTC.

Leap seconds are not inserted into GPS.

Therefore every time a leap second is inserted into UTC, UTC shifts another second with respect to GPS.

Aside from the offset from 1958y/January/1 to 1980y/January/Sunday[1], GPS is behind TAI by 19s due to the 10s offset between 1958 and 1970 and the additional 9 leap seconds inserted between 1970 and 1980.

2

#

gps_clock is not a Cpp17TrivialClock unless the implementation can guarantee thatgps_clock::now() does not propagate an exception.

[Note 1:

noexcept(from_utc(utc_clock::now())) is false.

— end note]

30.7.5.2 Member functions [time.clock.gps.members]

🔗

static time_point now();

1

#

Returns: from_utc(utc_clock::now()), or a more accurate value of gps_time.

🔗

template<class Duration> static utc_time<common_type_t<Duration, seconds>> to_utc(const gps_time<Duration>& t) noexcept;

2

#

Returns: utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 315964809s

[Note 1: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — end note]

🔗

template<class Duration> static gps_time<common_type_t<Duration, seconds>> from_utc(const utc_time<Duration>& t) noexcept;

3

#

Returns: gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 315964809s

[Note 2: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — end note]

30.7.5.3 Non-member functions [time.clock.gps.nonmembers]

🔗

template<class charT, class traits, class Duration> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const gps_time<Duration>& t);

1

#

Effects: Equivalent to:return os << format(os.getloc(), STATICALLY-WIDEN("{:L%F %T}"), t);

2

#

[Example 1: auto st = sys_days{2000y/January/1};auto gt = clock_cast<gps_clock>(st); cout << format("{0:%F %T %Z} == {1:%F %T %Z}\n", st, gt);

Produces this output:

2000-01-01 00:00:00 UTC == 2000-01-01 00:00:13 GPS

— 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, gps_time<Duration>& tp, basic_string<charT, traits, Alloc>* abbrev = nullptr, minutes* offset = nullptr);

3

#

Effects: Attempts to parse the input stream is into the gps_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) is called andtp is not 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.

4

#

Returns: is.