]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Format chrono %a/%A/%b/%h/%B/%p using locale's time_put [PR117214]
authorXU Kailiang <xu2k3l4@outlook.com>
Wed, 2 Jul 2025 07:10:29 +0000 (15:10 +0800)
committerTomasz Kamiński <tkaminsk@redhat.com>
Mon, 7 Jul 2025 13:55:11 +0000 (15:55 +0200)
commit8ad5968a8dcb472cbff8e4c48217fd65e125b2f2
treea56f2fcd5d1e7e11dbf78c11996ea05a769ffbe9
parent439b14e222571da76da2bfec04b9035fb9f1862d
libstdc++: Format chrono %a/%A/%b/%h/%B/%p using locale's time_put [PR117214]

C++ formatting locale could have a custom time_put that performs
differently from the C locale, so do not use __timepunct directly,
instead all of above specifiers use _M_locale_fmt.

For %a/%A/%b/%h/%B, the code handling the exception is now moved
to the _M_check_ok function, that is invoked before handling of the
conversion specifier. For time_points the values of months/weekday
are computed, and thus are always ok(), this information is indicated
by new _M_time_point member of the _ChronoSpec.

The different behavior of j specifier for durations and time_points/calendar
types, is now handled using only _ChronoParts, and _M_time_only in _ChronoSpec
is no longer needed, thus it was removed.

PR libstdc++/117214

libstdc++-v3/ChangeLog:

* include/bits/chrono_io.h (_ChronoSpec::_M_time_only): Remove.
(_ChronoSpec::_M_time_point): Define.
(__formatter_chrono::_M_parse): Use __parts to determine
interpretation of j.
(__formatter_chrono::_M_check_ok): Define.
(__formatter_chrono::_M_format_to): Invoke _M_check_ok.
(__formatter_chrono::_M_a_A, __formatter_chrono::_M_b_B): Move
exception throwing to _M_check_ok.
(__formatter_chrono::_M_j): Use _M_needs to define interpretation.
(__formatter_duration::_S_spec_for): Set _M_time_point.
* testsuite/std/time/format/format.cc: Test for exception for !ok()
months/weekday.
* testsuite/std/time/format/pr117214_custom_timeput.cc: New
test.

Co-authored-by: Tomasz Kaminski <tkaminsk@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: XU Kailiang <xu2k3l4@outlook.com>
Signed-off-by: Tomasz Kaminski <tkaminsk@redhat.com>
libstdc++-v3/include/bits/chrono_io.h
libstdc++-v3/testsuite/std/time/format/format.cc
libstdc++-v3/testsuite/std/time/format/pr117214_custom_timeput.cc [new file with mode: 0644]