Skip to content

gh-159712: Fix zero-based day rules in zoneinfo - #159723

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

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

Conversation

@pganssle

@pganssle pganssle commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Numeric TZ day rules currently transition one day early because both implementations use the same year baseline as one-based Julian rules. This accounts for the difference and adds local-time and UTC conversion tests for gaps, folds, leap days and the first and last days of the year, including day 365 of a common year falling on January 1 of the next year.

Fixes #159712. This depends on #159722, because correcting day zero exposes the year-boundary bug in permanent DST rules such as EST5EDT,0/0,J365/25. This draft includes that PR's commits until it is merged; the zero-based-day change is isolated in 5b2ce220a8b4a525d8d78d2caf4139baa844aa5d.

The new cases fail without the fix in both implementations. With the year-boundary fix and this change, ./python -m test test_zoneinfo passes all 285 tests, with 30 skips, on a debug build.

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.
@pganssle
pganssle force-pushed the fix-zoneinfo-159712 branch from 01ed192 to b66308e Compare October 19, 2026 18:38
@pganssle
pganssle force-pushed the fix-zoneinfo-159712 branch from b66308e to f498b34 Compare October 19, 2026 18:52
Numeric TZ day rules count January 1 as day zero, but both implementations
were using the same year baseline as one-based Julian rules. Account for
the difference so numeric rules no longer transition one day early.

Add local-time and UTC conversion cases for numeric rules, including gaps,
folds, leap days and the first and last days of the year.
@pganssle
pganssle force-pushed the fix-zoneinfo-159712 branch from f498b34 to 5b2ce22 Compare October 19, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZoneInfo evaluates zero-based TZ day-of-year rules one day early

1 participant