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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixed

- Allow `DateTime.astimezone()` to use the local timezone when no timezone argument is supplied, matching `datetime.datetime`.

- Arithmetic and `replace()` results for `Integer`, `Float`, `String`, `DateTime`, `Date` and `Time` no longer share the original item's `Trivia`, so changing the result's comment or indentation no longer rewrites the item still stored in the document.

## [0.15.2] - 2026-10-16
Expand Down
12 changes: 12 additions & 0 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,18 @@ def test_datetimes_behave_like_datetimes(tz_utc: tzinfo, tz_pst: tzinfo) -> None
assert doc.as_string() == "dt = 2018-07-23T12:34:56-05:00"


def test_datetime_astimezone_defaults_to_local_timezone() -> None:
value = parse("time = 1979-05-27T07:32:00Z # birthday\n")["time"]
expected = datetime(1979, 5, 27, 7, 32, tzinfo=timezone.utc).astimezone()

result = value.astimezone()

assert isinstance(result, DateTime)
assert result.unwrap() == expected
assert result.as_string() == expected.isoformat()
assert result == value.astimezone(None)


@pytest.mark.parametrize("fold", [0, 1])
def test_datetime_subtraction_preserves_input_fold(tz_fold: tzinfo, fold: int) -> None:
value = datetime(2018, 11, 4, 1, 30, tzinfo=tz_fold, fold=fold)
Expand Down
2 changes: 1 addition & 1 deletion tomlkit/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ def __sub__(self, other: timedelta | datetime) -> DateTime | timedelta:
def replace(self, *args: object, **kwargs: object) -> DateTime:
return self._new(super().replace(*args, **kwargs)) # type: ignore[arg-type]

def astimezone(self, tz: tzinfo) -> DateTime: # type: ignore[override]
def astimezone(self, tz: tzinfo | None = None) -> DateTime:
result = super().astimezone(tz)
if PY38:
return result
Expand Down
Loading