diff --git a/tests/test_items.py b/tests/test_items.py index cf6134aa..fa75f2b0 100644 --- a/tests/test_items.py +++ b/tests/test_items.py @@ -795,6 +795,20 @@ def test_datetime_subtraction_resets_result_fold( assert result.as_string() == expected.isoformat() +def test_unwrap_keeps_fold(tz_fold: tzinfo) -> None: + value = datetime(2018, 11, 4, 1, 30, tzinfo=tz_fold, fold=1) + unwrapped = item(value).unwrap() + + assert unwrapped.fold == value.fold + assert unwrapped.timestamp() == value.timestamp() + + clock = time(1, 30, tzinfo=tz_fold, fold=1) + unwrapped_time = item(clock).unwrap() + + assert unwrapped_time.fold == clock.fold + assert unwrapped_time.utcoffset() == clock.utcoffset() + + def test_dates_behave_like_dates() -> None: i = item(date(2018, 7, 22)) diff --git a/tomlkit/items.py b/tomlkit/items.py index 8589df97..f469bcac 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -1102,7 +1102,9 @@ def unwrap(self) -> datetime: _, _, ) = self._getstate() - return datetime(year, month, day, hour, minute, second, microsecond, tzinfo) + return datetime( + year, month, day, hour, minute, second, microsecond, tzinfo, fold=self.fold + ) @property def discriminant(self) -> int: @@ -1316,7 +1318,7 @@ def __init__( def unwrap(self) -> time: (hour, minute, second, microsecond, tzinfo, _, _) = self._getstate() - return time(hour, minute, second, microsecond, tzinfo) + return time(hour, minute, second, microsecond, tzinfo, fold=self.fold) @property def discriminant(self) -> int: