libstdc++: Do not require a time-of-day when parsing sys_days [PR114240]
commit3e8ee03edd018eed43444755f601cdb9d5931654
authorJonathan Wakely <jwakely@redhat.com>
Fri, 8 Mar 2024 16:15:57 +0000 (8 16:15 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Sat, 9 Mar 2024 00:21:42 +0000 (9 00:21 +0000)
tree0001f51fa1f7d4710dd49d7810c66a1a9577e2ce
parentf4a52c184d608325c14338b57f464f7d0bbc7526
libstdc++: Do not require a time-of-day when parsing sys_days [PR114240]

When parsing a std::chrono::sys_days (or a sys_time with an even longer
period) we should not require a time-of-day to be present in the input,
because we can't represent that in the result type anyway.

Rather than trying to decide which specializations should require a
time-of-date and which should not, follow the direction of Howard
Hinnant's date library, which allows extracting a sys_time of any period
from input that only contains a date, defaulting the time-of-day part to
00:00:00. This seems consistent with the intent of the standard, which
says it's an error "If the parse fails to decode a valid date" (i.e., it
doesn't care about decoding a valid time, only a date).

libstdc++-v3/ChangeLog:

PR libstdc++/114240
* include/bits/chrono_io.h (_Parser::operator()): Assume
hours(0) for a time_point, so that a time is not required
to be present.
* testsuite/std/time/parse/114240.cc: New test.
libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/testsuite/std/time/parse/114240.cc [new file with mode: 0644]