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 daylight saving time issue in shift function #1192

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

Conversation

Shaileshsaravanan
Copy link

@Shaileshsaravanan Shaileshsaravanan commented Oct 7, 2024

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

Fixes #1170: Correct DST Handling in shift Function

This PR addresses the issue with incorrect daylight saving time (DST) handling when using the shift function in the Arrow library.

Changes:

  • Modified the shift function to correctly handle transitions during DST changes.
  • Added logic to detect positive or negative offset changes when shifting across DST boundaries.
  • Adjusted the behavior during spring-forward (to skip the missing hour) and fall-back (to use the second occurrence of a repeated hour).

Issue Link:

Closes: #1170

Explanation:

Previously, the shift function did not account for the changes in offsets that occur during DST transitions, leading to unexpected behavior when shifting times. This fix ensures that:

  • For spring-forward transitions, any shifts that would land in the missing hour are adjusted forward.
  • For fall-back transitions, the repeated hour is handled properly by using the fold attribute to select the second occurrence.

Testing:

  • Added tests for time shifts that cross DST start and end dates to verify the behavior.
  • Ensured consistency when using timedelta shifts and repeated shifts.

@jadchaar
Copy link
Member

Hi @Shaileshsaravanan thanks for the PR. Mind getting the builds and tests passing? Then we can review :)

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.

incorrect behavior WRT daylight savings for shift/adding timedelta
2 participants