Skip to content

handle DST properly #1209 #1211

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

aurora324
Copy link

Pull Request Checklist

Thank you for taking the time to improve Arrow! Before submitting your pull request, please check all appropriate boxes:

  • 🧪 Added tests for changed code.
  • 🛠️ All tests pass when run locally (run tox or make test to find out!).
  • 🧹 All linting checks pass when run locally (run tox -e lint or make lint to find out!).
  • 📚 Updated documentation for changed code.
  • ⏩ Code is up-to-date with the master branch.

If you have any questions about your code changes or any of the points above, please submit your questions along with the pull request and we will try our best to help!

Description of Changes

Bug Fix

  • Fixed the time zone calculation error in the shift() method during DST transitions.
  • Original issue: Performing relativedelta operations directly on localized time caused errors during DST transition points.
  • New solution: Convert times with time zones to UTC for calculations, then convert them back to the original time zone.

Code Changes

# Original code (problematic code)
current = self._datetime + relativedelta(**relative_kwargs)

# Modified code (fixed code)
original_tz = self.tzinfo
if self._datetime.tzinfo is not None:
    utc_dt = self._datetime.astimezone(dateutil_tz.UTC)
    current = utc_dt + relativedelta(**relative_kwargs)
    current = current.astimezone(original_tz)
else:
    current = self._datetime + relativedelta(**relative_kwargs)

@@ -1035,7 +1035,14 @@ def shift(self, check_imaginary: bool = True, **kwargs: Any) -> "Arrow":
relative_kwargs.pop("quarters", 0) * self._MONTHS_PER_QUARTER
)

current = self._datetime + relativedelta(**relative_kwargs)
# current = self._datetime + relativedelta(**relative_kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding unit tests for this?

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