]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Format empty chrono-spec for the time points and hh_mm_ss directly.
authorTomasz Kamiński <tkaminsk@redhat.com>
Fri, 6 Jun 2025 09:32:27 +0000 (11:32 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Thu, 12 Jun 2025 14:26:04 +0000 (16:26 +0200)
commit8fa1e98493def5eb327397a587aa846f2145d634
tree9d9bcb7ec185ae32fc961d60a924136c4e352e1d
parent83a878c31b4f20d00638e44d689b04669247b0ed
libstdc++: Format empty chrono-spec for the time points and hh_mm_ss directly.

This patch change implementation of the formatters for time points and hh_mm_ss,
so they no longer delegate to operator<< for ostream in case of empty chrono-spec.
As in case of calendar types, the formatters for specific type now provide
__formatter_chrono with default _ChronoSpec that are used in case if empty
chrono-spec.

The configuration of __defSpec is straight forward, except for the sys_time,
and local_time that print time, if the duration is convertible to days,
which is equivalent to setting _M_chrono_specs "%F" instead of "%F %T".
Furthermore, certain sys_time<Dur> do not support ostream operator, and
should not be formattable with empty spec - in such case default
_M_chrono_spec, allowing the issue to still be detected in _M_parse.

Finally, _ChronoFormats are extended to cover required format strings.

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (_ChronoFormats::_S_ftz)
(_ChronoFormats::_S_ft, _ChronoFormats::_S_t): Define.
(__formatter_chrono::_M_format_to_ostream): Remove handling for
time_points.
(std::formatter<chrono::hh_mm_ss<_Dur>, _CharT>)
(std::formatter<chrono::sys_time<_Dur>, _CharT>)
(std::formatter<chrono::utc_time<_Dur>, _CharT>)
(std::formatter<chrono::tai_time<_Dur>, _CharT>)
(std::formatter<chrono::gps_time<_Dur>, _CharT>)
(std::formatter<chrono::file_time<_Dur>, _CharT>)
(std::formatter<chrono::local_time<_Dur>, _CharT>)
(std::formatter<chrono::__detail::__local_time_fmt<_Dur>, _CharT>)
(std::formatter<chrono::zoned_time<_Dur>, _CharT>):
Define __defSpec, and pass it as argument to _M_prase and
constructor of __formatter_chrono.
libstdc++-v3/include/bits/chrono_io.h