GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-73267: Fix tm_yday in time.strptime() when a week rolls over a year by Pixeless001 · Pull Request #161828 · python/cpython

Conversation

@Pixeless001

@Pixeless001 Pixeless001 commented Nov 11, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

time.strptime() accepts a week number (%U or %W) and a weekday that name a day after December 31. It resolves the date to the next year, but tm_yday keeps the count from the year in the input:

>>> time.strptime('2016 52 0', '%Y %W %w')[:3]
(2017, 1, 1)
>>> time.strptime('2016 52 0', '%Y %W %w').tm_yday
367
>>> time.strptime('2015 52 5', '%Y %U %w').tm_yday  # 2016-01-01
366

367 is outside the documented range, and 366 is the value for December 31. _strptime() already moves a week 0 day that falls before January 1 into the previous year. This change does the same at the other end of the year, so both calls return tm_yday=1.

Values given with %j are not changed: time.strptime('366', '%j').tm_yday is 366 today, and code can depend on that. GH-158459, which its author closed, changed that case too. I can add it if you want it.

Tested on Linux (WSL Ubuntu, gcc 15) with main at 0ada998. ./python -m test test_strptime test_time test_datetime passes. Without the change to Lib/_strptime.py, the new test_last_week fails with (2019, 1, 1, 0, 0, 0, 1, 366) != (2019, 1, 1, 0, 0, 0, 1, 1). ./python -m test -j8 passes except test_ssl, which fails the same way on unmodified main in my build (no zlib module).

The change is the elif block at Lib/_strptime.py:780, next to the existing week 0 branch.

  • Issue: time.strptime() with year rollover returns out-of-range tm_yday #73267

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Pixeless001
pythongh-73267: Fix tm_yday in time.strptime() when a week rolls over…
b22b051
… a year

A week number (%U or %W) and a weekday can name a day after December 31,
for example "2016 52 0" with "%Y %W %w", which is 2017-01-01. The date
fields were resolved to the next year, but tm_yday kept the day count
from the year in the input: 367 here, and 366 for 2016-01-01 parsed from
"2015 52 5" with "%Y %U %w".

A day in week 0 before January 1 is already moved to the previous year.
Do the same in the other direction, so that tm_yday matches the date.

Day numbers given with %j are not changed.
@Pixeless001
Pixeless001 requested review from StanFromIreland and pganssle as code owners November 11, 2026 20:42
@python-cla-bot

python-cla-bot Bot commented Nov 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot mentioned this pull request Nov 11, 2026
time.strptime() with year rollover returns out-of-range tm_yday #73267
Open
@bedevere-app bedevere-app Bot added the awaiting review label Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pganssle pganssle Awaiting requested review from pganssle pganssle is a code owner
@StanFromIreland StanFromIreland Awaiting requested review from StanFromIreland StanFromIreland is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Pixeless001
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.