Fix mixed calendar and fixed-unit arithmetic across DST - #1038
Open
pranavpk404 wants to merge 1 commit into
Open
pranavpk404 wants to merge 1 commit into
pranavpk404 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Fixes #838.
Summary
For aware datetimes, a mixed calendar/fixed-duration call currently applies all
units in naive local time. Reconstructing a time in a DST gap then normalizes
it forward, even when the requested fixed-duration shift was backwards.
For example, from
2024-04-01T04:00:00+03:00in Europe/Sofia:subtract(days=1)reaches2024-03-31T04:00:00+03:00.subtract(days=1, seconds=1)currently moves 3,599 seconds later.2024-03-31T02:59:59+02:00, one second earlier.Apply the existing calendar-only operation first, then the existing fixed-only
operation on the UTC timeline. This retains pure-calendar/fixed behavior and
the existing combined fractional rounding for naive datetimes. Document the
ordering for aware mixed-unit
addandsubtractcalls.Regression coverage
33 parametrized cases cover both methods and directions; days/weeks/months/years;
fractional seconds/calendar days; microseconds/minutes/hours; gaps and folds;
half-hour DST; multiple calendar units; UTC, naive and fixed-offset controls;
and subclasses. Elapsed-time expectations use independent stdlib arithmetic.
Validation
6394a10: full pure-Python suite 1882 passed, 3 skipped.prek run --all-files, including Ruff, Rust formatting and clippy: pass.git diff --check: pass.Validated on Linux / CPython 3.14.7 with current locked dependencies.
Pull Request Check List
AI assistance was used for investigation, implementation and tests. The source
changes, independent reproduction, and regression expectations were reviewed
before submission.