Default to own .fold when calling .replace()#414
Merged
sdispater merged 2 commits intopython-pendulum:masterfrom Jul 10, 2020
Merged
Default to own .fold when calling .replace()#414sdispater merged 2 commits intopython-pendulum:masterfrom
.fold when calling .replace()#414sdispater merged 2 commits intopython-pendulum:masterfrom
Conversation
43954db to
b984da8
Compare
b984da8 to
95ad44b
Compare
sdispater
reviewed
Jul 9, 2020
|
|
||
| def test_replace_tzinfo(): | ||
| d = pendulum.datetime(2016, 7, 2, 0, 41, 20) | ||
| def test_replace_tzinfo_dls_off(): |
Collaborator
There was a problem hiding this comment.
Why dls here and not dst?
Contributor
Author
There was a problem hiding this comment.
Oh right - I think I started off calling it "dls" (daylight-savings), but later saw that "dst" was a more common way to name it.
I'll rename to "dst".
Contributor
Author
There was a problem hiding this comment.
Fixed with a fixup commit (i.e. I can squash into one commit before merge if you like, unless if you want to just squash+merge)
Collaborator
|
Thanks! |
Merged
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.
After doing a lot of experiments, it seemed to me that there was a problem when calling
.replace()during DST off-transition (i.e. in the immediate hour after the transition). Reported issue here: #415.So a seemingly innocent code like this:
would change the datetime in more ways than simply setting microseconds to zero.
This patch makes it so that when
.replace()is called, it respects the.foldflag set on the datetime itself, which seems to resolve the issue.Now, I'm no expert in timezones myself, so this might definitely be the exact wrong approach - but my gut feeling told me that it seemed odd to just default to the
pendulum.POST_TRANSITIONrule anytime we do replace, so I figured utilizing the flag seemed the right way to go about it. Seemed more symmetrical to the surrounding code too.I added one more test module, to explicitly test out the
.replace()function. Wasn't sure where best to fit it, but can easily accommodate a different place for it. As it happened, one of the "fluent" tests also broke - one that is dong a.replace(tzinfo=...)call. So I suppose I could have put my replace tests there, but wasn't sure what "fluent" meant in this context. So I ended up adding a few more cases for those.replace(tzinfo=tests, to get solid coverage surrounding DST transition points. Not quite convinced if those tests are what you had in mind when you wrote the original test, so hoping I'm not deviating from the intended design.Well - looking forwards to your feedback - feel free to push back on any/all of this.