]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix std::chrono::parse for TAI and GPS clocks
authorJonathan Wakely <jwakely@redhat.com>
Wed, 4 Sep 2024 20:23:20 +0000 (21:23 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 6 Sep 2024 20:44:47 +0000 (21:44 +0100)
commit222ff1949a70997173aefe2e32d144661473d86b
treec17ed17cda6131ed718052e33ca20463f166c88f
parent1fa45e77154732af147e87aee1779a3b10db2b7a
libstdc++: Fix std::chrono::parse for TAI and GPS clocks

Howard Hinnant brought to my attention that chrono::parse was giving
incorrect values for chrono::gps_clock, because it was applying the
offset between the GPS clock and UTC. That's incorrect, because when we
parse HH::MM::SS as a GPS time, the result should be that time, not
HH:MM:SS+offset.

The problem was that I was using clock_cast to convert from sys_time to
utc_time and then using clock_time again to convert to gps_time. The
solution is to convert the parsed time into an duration representing the
time since the GPS clock's epoch, then construct a gps_time directly
from that duration.

As well as adding tests for correct round tripping of times for all
clocks, this also adds some more tests for correct results with
std::format.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (from_stream): Fix conversions in
overloads for gps_time and tai_time.
* testsuite/std/time/clock/file/io.cc: Test round tripping using
chrono::parse. Add additional std::format tests.
* testsuite/std/time/clock/gps/io.cc: Likewise.
* testsuite/std/time/clock/local/io.cc: Likewise.
* testsuite/std/time/clock/tai/io.cc: Likewise.
* testsuite/std/time/clock/utc/io.cc: Likewise.
libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/testsuite/std/time/clock/file/io.cc
libstdc++-v3/testsuite/std/time/clock/gps/io.cc
libstdc++-v3/testsuite/std/time/clock/local/io.cc
libstdc++-v3/testsuite/std/time/clock/tai/io.cc
libstdc++-v3/testsuite/std/time/clock/utc/io.cc