Skip to content

Fix: shift() loses fold, changes UTC offset on ambiguous DST time - #1362

Open
micson-bit wants to merge 2 commits into
arrow-py:masterfrom
micson-bit:fix-1067-shift-dst-offset
Open

micson-bit wants to merge 2 commits into
arrow-py:masterfrom
micson-bit:fix-1067-shift-dst-offset

Conversation

@micson-bit

Copy link
Copy Markdown

Fixes #1067

Problem

Calling .shift() on an Arrow object representing an ambiguous local time
(e.g. during a DST "fall back" transition) silently changes its UTC offset,
even when the shift amount is zero.

Root cause

In Arrow.shift(), the line:

current = self._datetime + relativedelta(**relative_kwargs)

rebuilds the datetime via relativedelta, which does not preserve the
original fold value. fold is what disambiguates repeated wall-clock
times during a DST transition. Without it, the reconstructed datetime
defaults to fold=0, causing Arrow to resolve to the wrong occurrence
of the ambiguous time.

Fix

Re-apply the original fold value immediately after the relativedelta
addition, before any further processing:

current = dateutil_tz.enfold(current, fold=self._datetime.fold)

Testing

Added test_shift_zero_seconds_preserves_offset_on_ambiguous_dst_time in
tests/test_arrow.py, which reproduces the bug from #1067. Confirmed it
fails before the fix and passes after. Full test suite (226 tests) still
passes.

@codecov

codecov Bot commented Sep 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 (987bb8a).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1362   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2316    +1     
  Branches       358       358           
=========================================
+ Hits          2315      2316    +1     

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

This branch has not been deployed

No deployments
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.

Issue with the timezone preserving while invoking the shift method.

1 participant