FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-159714: Fix ZoneInfo Julian day 59 in leap years by pganssle · Pull Request #159721 · python/cpython · GitHub

Repository navigation

gh-159714: Fix ZoneInfo Julian day 59 in leap years - #159721

Merged
StanFromIreland merged 1 commit into
python:mainfrom
pganssle:fix-zoneinfo-159714
Oct 21, 2026
Merged

StanFromIreland merged 1 commit into
python:mainfrom
pganssle:fix-zoneinfo-159714

Conversation

pganssle commented Oct 19, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Fixes #159714.

J59 in a TZ string always means February 28, but both ZoneInfo implementations were adding a leap day starting at day 59. This moves the adjustment to day 60, so J59 remains February 28 and J60 remains March 1.

The regression cases cover J59 as both the start and end of DST, along with neighboring J58 and J60 rules, including gaps, folds and UTC conversion in common and leap years. They include century years on both sides of the leap-year rule.

./python -m test test_zoneinfo -v passes on a debug build, with 277 tests run and 30 skipped. Reverting the fix produces 18 failures in the shared tests, covering both implementations and both local-time lookup and UTC conversion.

Julian day 59 is February 28 in every year, but both implementations
were applying the leap-day adjustment starting at day 59. Apply it
starting at day 60 instead.

Add regression cases for J59 as both the start and end of DST, including
gaps, folds and UTC conversion in leap and common years.
Comment thread Modules/_zoneinfo.c
Comment on lines 1422 to 1425
// We subtract off an additional 1 day to account for January 1st (we want
// the number of full days *before* the date of the transition - partial
// days are accounted for in the hour, minute and second portions.
int64_t days_before_year = ymd_to_ord(year, 1, 1) - EPOCHORDINAL - 1;

StanFromIreland Oct 19, 2026 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hmmm, the - 1 here is only right for the one-based Jn form, where J1 is January 1. For the zero-based n form, 0 is already January 1, so adding day to this base lands every n rule one day early....

>>> import datetime
... import io
... import struct
... import zoneinfo
... from zoneinfo import _zoneinfo
... 
... 
... def tzif(footer: bytes) -> io.BytesIO:
...     # A TZif v3 file with no explicit transitions.
...     header = b"TZif3" + b"\0" * 15 + struct.pack(">6l", 0, 0, 0, 0, 1, 4)
...     body = struct.pack(">lbb", 0, 0, 0) + b"STD\0"
...     return io.BytesIO(header + body + header + body + b"\n" + footer + b"\n")
... 
... 
... for implementation in (zoneinfo, _zoneinfo):
...     tz = implementation.ZoneInfo.from_file(tzif(b"STD0DST-1,59/0,J300/0"))
...     print(implementation.__name__)
...     for year in (2023, 2024):
...         local = datetime.datetime(year, 2, 28, 12, tzinfo=tz)
...         print(local.date(), local.tzname())
...         
zoneinfo
2023-02-28 DST
2024-02-28 DST
zoneinfo._zoneinfo
2023-02-28 DST
2024-02-28 DST

I'd expect STD in both years as day 59 is March 1 in 2023 and February 29 in 2024, so February 28 is still before the transition. Another fun bug (isn't it great when patches find bugs ;-)!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Oh wait, I just looked through the issues, you already have it as #159712

StanFromIreland added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 21, 2026
StanFromIreland merged commit 16c0adc into python:main Oct 21, 2026
67 checks passed

Copy link
Copy Markdown

Thanks @pganssle for the PR, and @StanFromIreland for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

bedevere-app Bot commented Oct 21, 2026

Copy link
Copy Markdown

GH-160052 is a backport of this pull request to the 3.15 branch.

bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 21, 2026

bedevere-app Bot commented Oct 21, 2026

Copy link
Copy Markdown

GH-160053 is a backport of this pull request to the 3.14 branch.

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 21, 2026
StanFromIreland pushed a commit that referenced this pull request Oct 21, 2026
…) (#160053)

(cherry picked from commit 16c0adc)

Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
StanFromIreland pushed a commit that referenced this pull request Oct 21, 2026
…) (#160052)

(cherry picked from commit 16c0adc)

Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 TZ rule J59 as February 29 in leap years

2 participants


Back | FazBrowse Home | New Git URL