Skip to content

gh-73267: Normalize strptime day of year after rollover - #158459

Open
zolaski333 wants to merge 1 commit into
python:mainfrom
zolaski333:codex/gh-73267-strptime-yday
Open

zolaski333 wants to merge 1 commit into
python:mainfrom
zolaski333:codex/gh-73267-strptime-yday

Conversation

@zolaski333

@zolaski333 zolaski333 commented Sep 29, 2026 •

Copy link
Copy Markdown

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.

@python-cla-bot

python-cla-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

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.

time.strptime() with year rollover returns out-of-range tm_yday

1 participant