Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
6 changes: 4 additions & 2 deletions tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Loading