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

fix: handle DST folded dates with start/end_of #713

Conversation

nekonyuu
Copy link
Contributor

@nekonyuu nekonyuu commented Jun 14, 2023

The bug

While implementing pendulum usage where I work (switching from buggy arrow DST handling), I've found a bug around start_of/end_of handling of dates, when the passed date is exactly in the ambiguous hour period (going out of DST).

For example :

>>> d = pendulum.datetime(2013, 10, 27, 0, 59, 59, tz="UTC").in_timezone("Europe/Paris")
>>> d.isoformat()
'2013-10-27T02:59:59+02:00'
>>> d.start_of("hour").isoformat()
'2013-10-27T02:00:00+01:00'

Here, the expected behavior would be that I still get the offset from the current hour (as I didn't transition).
The end_of method suffer of the same bug.

Fix proposal

I'm not that familiar with Python and its internal about fold, but reading the PEP, I've found that simply porting the fold field from the original date is enough, as we were missing the information that the date either didn't happen yet, or did.

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

@nekonyuu nekonyuu force-pushed the bugfix/start-end-of-tz-offset-management-on-ambiguous-period branch from 76d2eb1 to 3419def Compare June 14, 2023 12:49
@sdispater sdispater merged commit 599b44b into python-pendulum:master Aug 17, 2023
@sdispater
Copy link
Collaborator

Thanks!

@nekonyuu nekonyuu deleted the bugfix/start-end-of-tz-offset-management-on-ambiguous-period branch October 10, 2023 11:30
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

Successfully merging this pull request may close these issues.

2 participants