gh-73267: Normalize strptime day of year after rollover - #158459
Open
zolaski333 wants to merge 1 commit into
Open
zolaski333 wants to merge 1 commit into
zolaski333 wants to merge 1 commit into
Conversation
zolaski333
marked this pull request as ready for review
September 29, 2026 23:20
zolaski333
requested review from
StanFromIreland and
pganssle
as code owners
September 29, 2026 23:20
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
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.
Bug
time.strptime("2016 52 0", "%Y %W %w")resolves to 2017-01-01 but currently returnstm_yday=367. This is outside the documented 1–366 range; on Windows, passing the result totime.strftime()raisesValueError. A rollover from%Uor%jcan also leave a valid-looking but incorrecttm_yday._strptimeconverts the ordinal to a date and updates its year, month, and day, but leavesjulianrelative to the input year. Recomputejulianfrom the resolved date when the year changes.Tests
%W,%U, and%jcrossing 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.-X dev -m test -j4): 50,966 tests run; 443 test files passed, 3 unrelated files failed.test_os.test_device_encodingfails because this runner presents stdin as a TTY butos.device_encoding(0)isNone(the module passes with piped stdin).test_posixpath.test_realpath_invalid_pathsexpectsFileNotFoundErrorfor a NUL path but getsValueError(reproduces in isolation).test_ssl.test_pha_required_nocertsaw 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.