Skip to content

Fix DST fall-back repeated hour skipped in Arrow.range() (#1162)#1282

Open
Abdu-Ahmed wants to merge 1 commit into
arrow-py:masterfrom
Abdu-Ahmed:fix/dst-fall-back-range-skips-repeated-hour-1162
Open

Fix DST fall-back repeated hour skipped in Arrow.range() (#1162)#1282
Abdu-Ahmed wants to merge 1 commit into
arrow-py:masterfrom
Abdu-Ahmed:fix/dst-fall-back-range-skips-repeated-hour-1162

Conversation

@Abdu-Ahmed

Copy link
Copy Markdown

Closes #1162

When arrow.get() was called with an offset-aware string and a named
tzinfo kwarg (e.g. arrow.get("2021-11-07T01:00:00-05:00", tzinfo="US/Eastern")),
the tzinfo was replaced rather than used for conversion. This caused
the UTC moment to shift and fold information to be lost, so Arrow.range()
skipped the repeated hour during DST fall-back (returning 2 hours instead of 3).

Fix 1 (factory.py): When a parsed string already has offset info and
a tzinfo kwarg is provided, convert using .to() instead of replacing,
preserving the original UTC moment.

Fix 2 (arrow.py): In fromdatetime(), when replacing tzinfo, infer
the correct fold by comparing the original UTC offset against what fold=1
produces in the new timezone.

All 1901 tests pass (99.93% coverage).

@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2224255) to head (9f060d0).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1282   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2324    +9     
  Branches       358       361    +3     
=========================================
+ Hits          2315      2324    +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

….range()

When arrow.get() was called with an offset-aware string and a named
tzinfo kwarg (e.g. arrow.get('2021-11-07T01:00:00-05:00', tzinfo='US/Eastern')),
the tzinfo was replaced rather than used for conversion. This caused
the UTC moment to change and the fold to be lost, so Arrow.range()
would skip the repeated hour during DST fall-back.

Fix 1 (factory.py): When a string with offset info is parsed and a
tzinfo kwarg is provided, convert using .to() instead of replacing,
preserving the original UTC moment.

Fix 2 (arrow.py): In fromdatetime(), when replacing tzinfo, infer
the correct fold by comparing the original UTC offset against what
fold=1 produces in the new timezone.
@Abdu-Ahmed Abdu-Ahmed force-pushed the fix/dst-fall-back-range-skips-repeated-hour-1162 branch from a880b2c to 9f060d0 Compare May 25, 2026 10:17
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.

Missing hour during DST long day when shifting or calculating ranges

1 participant