From 057ceb1fbf23e4035ca9e7550db08e5057e56ae6 Mon Sep 17 00:00:00 2001 From: Gray Memory Bot Date: Sun, 7 Jun 2026 09:35:05 -0400 Subject: [PATCH] fix: Arrow shift method is not handling DST properly --- arrow/arrow.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arrow/arrow.py b/arrow/arrow.py index eecf23266..3c890d842 100644 --- a/arrow/arrow.py +++ b/arrow/arrow.py @@ -998,7 +998,7 @@ def shift(self, check_imaginary: bool = True, **kwargs: Any) -> "Arrow": according to inputs. Parameters: - check_imaginary (bool): If True (default), will check for and resolve + check_imaginary (bool): If True (default), checks for and resolves imaginary times (like during DST transitions). If False, skips this check. @@ -1048,9 +1048,11 @@ def shift(self, check_imaginary: bool = True, **kwargs: Any) -> "Arrow": current = self._datetime + relativedelta(**relative_kwargs) - # If check_imaginary is True, perform the check for imaginary times (DST transitions) - if check_imaginary and not dateutil_tz.datetime_exists(current): - current = dateutil_tz.resolve_imaginary(current) + if check_imaginary: + # Check if the resulting datetime exists (not imaginary during DST transition) + if not dateutil_tz.datetime_exists(current): + # Resolve imaginary time by adjusting to the appropriate DST offset + current = dateutil_tz.resolve_imaginary(current) return self.fromdatetime(current)