Skip to content

gh-159715: Fix ZoneInfo TZ rules spanning year boundaries - #159722

Open
pganssle wants to merge 5 commits into
python:mainfrom
pganssle:fix-zoneinfo-159715
Open

pganssle wants to merge 5 commits into
python:mainfrom
pganssle:fix-zoneinfo-159715

Conversation

@pganssle

@pganssle pganssle commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Fixes #159715.

TZ footer rules can put a transition in a different year from the rule that defines it. The lookup now considers neighboring DST periods, including periods that touch to represent permanent DST. This fixes incorrect offsets and UTC round trips near New Year in both implementations. Folds are based on an actual decrease in offset, so dummy transitions between permanent-DST periods don't create a fold.

The tests cover positive and negative DST, displaced start and end rules, extended transition hours, years 1 and 9999, and short DST periods where only part of the nominal fold is ambiguous. The Python implementation retains a single-year lookup away from year boundaries when the rules are far enough apart that their order cannot change between years.

Validation: ./python -m test test_zoneinfo passes on a debug build. The year-boundary regressions fail with the original implementations restored.

TZ string lookups only considered rules from the datetime's year, even
when an offset or extended transition time moved a rule into a different
year. Consider neighboring DST periods and join touching periods so that
permanent DST does not introduce a gap or fold at New Year.

Determine folds from actual offset changes. This also avoids marking
times as ambiguous when the first occurrence would have fallen in a gap
at the start of a short DST period. Keep the Python single-year lookup
away from year boundaries when the rule order cannot change between years,
to avoid scanning neighboring periods for ordinary footer lookups.

Add regressions for both implementations, including positive and negative
DST, extended transition hours, and datetime's extreme years.
Comment thread Lib/test/test_zoneinfo/test_zoneinfo.py
Comment thread Lib/test/test_zoneinfo/test_zoneinfo.py
Comment thread Lib/zoneinfo/_zoneinfo.py Outdated
Comment thread Lib/zoneinfo/_zoneinfo.py Outdated
Comment thread Lib/zoneinfo/_zoneinfo.py Outdated
Comment thread Lib/zoneinfo/_zoneinfo.py Outdated
Comment thread Lib/zoneinfo/_zoneinfo.py Outdated
Comment thread Lib/zoneinfo/_zoneinfo.py Outdated
Comment thread Lib/zoneinfo/_zoneinfo.py Outdated
@pganssle
pganssle marked this pull request as ready for review October 19, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZoneInfo mishandles TZ footer rules spanning a year boundary

1 participant