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
13 changes: 13 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ def test_date() -> None:
tomlkit.date("12:34:56")


@pytest.mark.parametrize(
"raw",
[
"1979-05-13T12:34:56",
"1979-05-13T12:34:56Z",
"1979-05-13T12:34:56+02:00",
],
)
def test_date_rejects_datetime_strings(raw: str) -> None:
with pytest.raises(ValueError, match=r"date\(\) only accepts date strings"):
tomlkit.date(raw)


def test_time() -> None:
dt = tomlkit.time("12:34:56")

Expand Down
2 changes: 1 addition & 1 deletion tomlkit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def string(
def date(raw: str) -> Date:
"""Create a TOML date."""
value = parse_rfc3339(raw)
if not isinstance(value, _datetime.date):
if isinstance(value, _datetime.datetime) or not isinstance(value, _datetime.date):
raise ValueError("date() only accepts date strings.")

return item(value)
Expand Down
Loading