[Bug libstdc++/124851] std::chrono::time_zone reports wrong total offset for zones whose RULES field is a numeric DST save value

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jul 31 10:56:10 GMT 2026


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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Tomasz Kaminski
<tkaminsk@gcc.gnu.org>:

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

commit r14-12776-ga4aac975dbc905e0a57dbf3c3f56185e93f0203e
Author: Álvaro Begué <alvaro.begue@gmail.com>
Date:   Sun Apr 26 19:51:17 2026 -0400

    libstdc++: Fix numeric save offset on Zone lines [PR124851]

    When a Zone line specifies a numeric value as its RULES field (the
    constant DST save value for that zone line, e.g. Africa/Gaborone's
    "2 1 CAST" line), the parser stored the standard offset alone in
    ZoneInfo::m_offset. ZoneInfo::to() then returned that as
    sys_info::offset, dropping the numeric save and reporting a total
    offset that was wrong by the save amount.

    This was inconsistent with the two ZoneInfo constructors that take a
    sys_info, which previously stored the *total* offset (stdoff + save) in
    m_offset. As a result m_offset's semantics depended on which code path
    created the ZoneInfo, and only the parser path's lines with non-zero
    numeric save were observably broken.

    Fix by giving m_offset a single semantics: always the standard offset
    only. The two sys_info-taking constructors now subtract the save before
    storing, and to(0 adds it back when reconstructing the sys_info.

    The remaining .offset() callers inside _M_get_sys_info already expect
    the standard offset (they are computing rule firing times, where the
    save component is added separately from the active rule's save value),
    so no other call sites need adjustment.

    libstdc++-v3/ChangeLog:

            PR libstdc++/124851
            * src/c++20/tzdb.cc (ZoneInfo::ZoneInfo(sys_info&&)): Store
            stdoff only in m_offset (subtract info.save).
            (ZoneInfo::ZoneInfo(const pair<sys_info, string_view>&)):
            Likewise.
            (ZoneInfo::offset()): Document new semantics.
            (ZoneInfo::to(sys_info&)): Add m_save back to offset() when
            populating sys_info::offset.
            * testsuite/std/time/time_zone/numeric_save.cc: New test.

    Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
    Reviewed-by: Tomasz KamiÅski <tkaminsk@redhat.com>
    Signed-off-by: Álvaro Begué <alvaro.begue@gmail.com>
    (cherry picked from commit 864f26bd7548d1a290b334b8f5375199449fcff5)


More information about the Gcc-bugs mailing list