GeezerVison is showing github.com — gh-73267: Normalize strptime day of year after rollover by zolaski333 · Pull Request #158459 · python/cpython
Conversation
zolaski333
commented
Sep 29, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Bug
time.strptime("2016 52 0", "%Y %W %w") resolves to 2017-01-01 but currently returns tm_yday=367. This is outside the documented 1–366 range; on Windows, passing the result to time.strftime() raises ValueError. A rollover from %U or %j can also leave a valid-looking but incorrect tm_yday.
_strptime converts the ordinal to a date and updates its year, month, and day, but leaves julian relative to the input year. Recompute julian from the resolved date when the year changes.
Tests
- Added regression cases for
%W, %U, and %j crossing into the next year. These failed before the fix and pass afterward.
PCbuild\amd64\python.exe -X dev -m test test_strptime test_time test_datetime: 1,292 tests run, 123 skipped; success.
PCbuild\amd64\python.exe Tools\patchcheck\patchcheck.py: success.
- Full local Windows suite (
-X dev -m test -j4): 50,966 tests run; 443 test files passed, 3 unrelated files failed. test_os.test_device_encoding fails because this runner presents stdin as a TTY but os.device_encoding(0) is None (the module passes with piped stdin). test_posixpath.test_realpath_invalid_paths expects FileNotFoundError for a NUL path but gets ValueError (reproduces in isolation). test_ssl.test_pha_required_nocert saw a localized Windows connection-reset message that did not match its English regex (the module passes in isolation).
Fixes #73267.
AI assistance was used to investigate and prepare this change. The patch and test results were reviewed before submission.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
All commit authors signed the Contributor License Agreement.

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
pganssle
Awaiting requested review from pganssle
pganssle is a code owner
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
Milestone
No milestone
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.