Skip to content

Commit 2ca8e36

Browse files
tobixenclaude
andcommitted
fix: catch ValueError in _to_utc_date_string for year-1 datetimes
astimezone(utc_tz) on a naive datetime near year 1 can raise ValueError ("year must be in 1..9999, not 0") when the local timezone offset shifts the date before year 1, not only OverflowError/OSError as previously assumed. Fixes tests TestErrorUnitTestBot::test_to_utc_date_string_with_exception and TestRegressionUnitTestBot::test_to_utc_date_string_min broken by e9a053a. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 62c37a7 commit 2ca8e36

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

caldav/elements/cdav.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _to_utc_date_string(ts):
2020
## in python 3.6 and higher, ts.astimezone() will assume a
2121
## naive timestamp is localtime (and so do we)
2222
ts = ts.astimezone(utc_tz)
23-
except (OverflowError, OSError):
23+
except (OverflowError, OSError, ValueError):
2424
## native time stamp and the current python version is
2525
## not able to treat it as localtime.
2626
import tzlocal

0 commit comments

Comments
 (0)