[time.clock.gps] # 30 Time library [[time]](./#time) ## 30.7 Clocks [[time.clock]](time.clock#gps) ### 30.7.5 Class gps_clock [time.clock.gps] #### [30.7.5.1](#overview) Overview [[time.clock.gps.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; using time_point = chrono::time_point; static constexpr bool is_steady = *unspecified*; static time_point now(); templatestatic utc_time> to_utc(const gps_time&) noexcept; templatestatic gps_time> from_utc(const utc_time&) noexcept; };} [1](#overview-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3223) The clock gps_clock measures seconds since the first Sunday of January, 1980 00:00:00 UTC[.](#overview-1.sentence-1) Leap seconds are not inserted into GPS[.](#overview-1.sentence-2) Therefore every time a leap second is inserted into UTC, UTC shifts another second with respect to GPS[.](#overview-1.sentence-3) 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[.](#overview-1.sentence-4) [2](#overview-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3233) gps_clock is not a [*Cpp17TrivialClock*](time.clock.req#:Cpp17TrivialClock "30.3 Cpp17Clock requirements [time.clock.req]") unless the implementation can guarantee thatgps_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.5.2](#members) Member functions [[time.clock.gps.members]](time.clock.gps.members) [🔗](#lib:now,gps_clock) `static time_point now(); ` [1](#members-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3249) *Returns*: from_utc(utc_clock​::​now()), or a more accurate value of gps_time[.](#members-1.sentence-1) [🔗](#lib:to_utc,gps_clock) `template static utc_time> to_utc(const gps_time& t) noexcept; ` [2](#members-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3262) *Returns*: utc_time>{t.time_since_epoch()} + 315964809s [*Note [1](#members-note-1)*: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — *end note*] [🔗](#lib:from_utc,gps_clock) `template static gps_time> from_utc(const utc_time& t) noexcept; ` [3](#members-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3282) *Returns*: gps_time>{t.time_since_epoch()} - 315964809s [*Note [2](#members-note-2)*: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s — *end note*] #### [30.7.5.3](#nonmembers) Non-member functions [[time.clock.gps.nonmembers]](time.clock.gps.nonmembers) [🔗](#lib:operator%3c%3c,gps_time) `template basic_ostream& operator<<(basic_ostream& os, const gps_time& t); ` [1](#nonmembers-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3304) *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#L3311) [*Example [1](#nonmembers-example-1)*: auto st = sys_days{2000y/January/1};auto gt = clock_cast(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*] [🔗](#lib:from_stream,gps_time) `template> basic_istream& from_stream(basic_istream& is, const charT* fmt, gps_time& tp, basic_string* abbrev = nullptr, minutes* offset = nullptr); ` [3](#nonmembers-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/time.tex#L3337) *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]](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#L3353) *Returns*: is[.](#nonmembers-4.sentence-1)