Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad results using .replace() during DST transitioning off #415

Closed
tomage opened this issue Oct 16, 2019 · 1 comment
Closed

Bad results using .replace() during DST transitioning off #415

tomage opened this issue Oct 16, 2019 · 1 comment

Comments

@tomage
Copy link
Contributor

tomage commented Oct 16, 2019

Hi sdispater!

First of all - thanks for this library - my company started out with arrow because it seemed easy etc.. But man, are there drawbacks... Pendulum seems to be doing things the right way, so thanks a lot for crafting this.

Now - I've been digging fairly deep into DST transitions recently, and I think I may have discovered 2 small bugs. To start with, I'll start with the (hopefully) more straight-forward one here (the other is #417).

Seems that if one has a datetime in the hour after DST transitions off, and then does a .replace(seconds=0), it messes up the DST information on the DateTime object.

>>> # Daylight savings turning off for US/Pacific in 2019 
>>> # happenes on the 3rd of November, at 9:00 UTC
>>> dt = pendulum.datetime(2019, 11, 3, 8, 30, 12)
>>> tz = pendulum.timezone('US/Pacific')
>>> dtz = tz.convert(dt)
>>> print(dtz.isoformat())
2019-11-03T01:30:12-07:00
>>> print(dtz.fold, dtz.is_dst(), -dtz.utcoffset())
0 True 7:00:00

>>> dtz2 = dtz.replace(second=0)
>>> print(dtz2.isoformat())
2019-11-03T01:30:00-08:00
>>> print(dtz2.fold, dtz2.is_dst(), -dtz2.utcoffset())
1 False 8:00:00

I took the liberty of trying my hand at a fix: #414.

I set up a small pyfiddle showcasing the behavior: https://pyfiddle.io/fiddle/d80564bc-96ca-4fe8-9e3e-982a474e9e73/?i=true

@tomage
Copy link
Contributor Author

tomage commented Jul 10, 2020

Fixed with #414 (comment)!

@tomage tomage closed this as completed Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant