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

--- Comment #2 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:b9a2dfbd3914d23c2e2284ce03decb0be19fa2cb

commit r16-4348-gb9a2dfbd3914d23c2e2284ce03decb0be19fa2cb
Author: Tomasz KamiÅski <[email protected]>
Date:   Thu Oct 9 14:38:54 2025 +0200

    libstdc++: Improve handling of !ok() weekday index in formatting [PR121929]

    Previously, formatting a year_month_weekday with the weekday index equal to
    0, 6, or 7 (which are !ok() values in the supported range) produced a
    seemingly correct day output. For example %Y-%m-%d produced:
     * 2024-09-06 for 2024y/September/Sunday[6] (2024-10-06)
     * 2024-09-25 for 2024y/September/Sunday[0] (2023-08-25)

    This patch changes how the internal _M_day value is computed for
    year_month_weekday. Instead of converting to local_days then to
year_month_day,
    _M_day is now set as the number of days since ymd.year()/ymd.month()/0. If
this
    difference is negative (which occurs when index() is 0), _M_day is set to 0
to
    avoid handling negative days of the month.

    This change yields identical results for all ok() values. However, for
!ok() dates,
    it now consistently produces invalid dates, ensuring the formatted output
clearly
    reflects the !ok input state:
     * 2024-09-36 for 2024y/September/Sunday[6]
     * 2024-09-00 for 2024y/September/Sunday[0]

    For consistency, _M_day is computed in the same manner for
year_month_weekday_last.

    Finally, for year_month_day_last, we fill _M_day directly with ymd.day().
    This provides a more efficient implementation and avoids the need to
compute
    local_days for %Y-%m-%d, %F and similar specifiers.

            PR libstdc++/121929

    libstdc++-v3/ChangeLog:

            * include/bits/chrono_io.h (_ChronoData::_M_fill_aux)
            (_ChronoData::_M_fill_aux): Add comment documenting precondition.
            (formatter<chrono::year_month_day, _CharT>::format): Compute
            local_days inline.
            (formatter<chrono::year_month_day_last, _CharT>::format)
            (formatter<chrono::year_month_weekday, _CharT>::format)
            (formatter<chrono::year_month_weekday_last, _CharT>::format):
            Change how the _M_day field is computed.
            * testsuite/std/time/year_month_weekday/io.cc: Adjust tests.

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

Reply via email to