Default to own .fold
when calling .replace()
#414
Merged
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.fold
flag 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_TRANSITION
rule 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.