https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120481

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tomasz Kaminski <[email protected]>:

https://gcc.gnu.org/g:c45cc9423d5fca4635865e1d4bc858a4a6f4d65b

commit r16-1170-gc45cc9423d5fca4635865e1d4bc858a4a6f4d65b
Author: Tomasz KamiÅski <[email protected]>
Date:   Mon Jun 2 09:06:56 2025 +0200

    libstdc++: Fix formatting of 3-digits months,day,weekday and hour
[PR120481]

    This patch fixes the handle multiple digits values for the month, day,
weekday
    and hour, when used with the %m, %d, %e, %m, %u, %w, %H, and %D, %F
specifiers.
    The values are now  printed unmodified. This patch also fixes printing
negative
    year with %F, where the values was not padded to four digits.

    Furthemore, the %I,%p are adjusted to handle input with hours values set to
    over 24 hours. In the case the values is interpretd modulo 24. This was
already
    the case for %r (locale's 12-hour clock), as we convert the input into
seconds.

    In case of %u, %w we print values unchanged, this makes the behavior of
this
    specifiers equivalent to printing the iso_encoding and c_encoding
respectively.
    As constructing weekday from value 7, initializes it with 0, the !ok()
weekdays
    values are always greater of equal eight, so they are clearly
distinguishable.

    The months, weekday, day values that can have 3 decimal digit as maximum
    (range [0, 255]), we are using new _S_str_d1, _S_str_d2 that return
string_view
    containing textual representation, without padding or padded to two digits.
    This function accepts are 3 character buffer, that are used for 3 digits
number.
    In other cases, we return _S_digit and _S_two_digits result directly. The
former
    is changed to return string_view to facilitate this.

    For %F and %D when at least one component have more digits that expected (2
for
    month and day, 4 for year), we produce output using format_to with
appropriate
    format string. Otherwise the representation is produced in local char
buffer.
    Two simply fill this buffer, _S_fill_two_digits function was added. We also
    make sure that minus is not included in year width for %F.

    The handling of %C, %Y, %y was adjusted to use similar pattern, for years
with
    more than two digits. To support that the order of characters in _S_chars
was
    adjusted so it contain "-{}" string.

    For handling of %H, we print 3 or more digits values using format_to. The
handling
    for large hours values in %T and %R was changed, so they printed using
format_to,
    and otherwise we use same stack buffer as for minutes to print them.

            PR libstdc++/120481

    libstdc++-v3/ChangeLog:

            * include/bits/chrono_io.h (__format::_S_chars): Reorder so it
            contains "-{}".
            (__format::_S_colon, __format::_S_slash, __format::_S_space)
            (__format::_S_plus_minus): Updated starting indicies.
            (__format::_S_minus_empty_spec): Define.
            (__formatter_chrono::_M_C_y_Y, __formatter_chrono::_M_R_T):
            Rework implementation.
            (__formatter_chrono::_M_d_e, __formatter_chrono::_M_F)
            (__formatter_chrono::_M_m, __formatter_chrono::_M_u_w)
            (__formatter_chrono::_M_H_I, __formatter_chrono::_M_p):
            Handle multi digits values.
            (__formatter_chrono::_S_digit): Return string view.
            (__formatter_chrono::_S_str_d1, __formatter_chrono::_S_str_d2)
            (__formatter_chrono::_S_fill_two_digits): Define.
            * testsuite/std/time/format/empty_spec.cc: Update test for
            year_month_day, that uses '%F'.
            * testsuite/std/time/format/pr120481.cc: New test.

    Reviewed-by: Jonathan Wakely <[email protected]>
    Signed-off-by: Tomasz KamiÅski <[email protected]>

Reply via email to