Repository navigation
fix(tz): reset fold to 0 for unambiguous local times - #1057
Open
saadkhantareen wants to merge 1 commit into
Open
saadkhantareen wants to merge 1 commit into
saadkhantareen wants to merge 1 commit into
Conversation
DateTime.create() resolves new instances with fold=1 so that ambiguous times default to their second occurrence, but Timezone.convert() kept that fold value for every local time. As a result, ordinary datetimes reported fold=1, and the value changed inconsistently depending on the operation performed (minute additions reset it, day additions kept it). Timezone.convert() now sets fold to 0 when the converted local time is not ambiguous, per PEP 495. DateTime.set() only carries the current fold over to the new time when the current time is actually ambiguous, so fluent setters keep resolving DST gaps and overlaps with the default rules otherwise.
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.
Summary
Fixes #853.
Datetimes created for ordinary, unambiguous local times reported a bogus
foldvalue of 1, and the value changed inconsistently depending on the operation performed:Per PEP 495,
foldmust be 0 for local times that are not ambiguous.Changes
Timezone.convert(): after normalizing a naive datetime, resetfoldto 0 when the resulting local time is not ambiguous (its UTC offset is the same forfold=0andfold=1). Ambiguous times keep the fold they were resolved with, so the existing default of resolving repeated times to their second occurrence is unchanged, as is the fold-based resolution of skipped times.DateTime.set(): only carry the currentfoldover to the new time when the current time is actually ambiguous. Otherwise the meaningless fold of an unambiguous time decided how a new time falling in a DST gap or overlap was resolved; the default resolution ofDateTime.create()now applies, which preserves the existing behavior of fluent setters such asat()around transitions.Timezone.convert(),pendulum.datetime()withadd(), ambiguous times keeping their fold, andset()on an ambiguous time.Tests
Pull Request Check List