mirror of
https://github.com/home-assistant/core.git
synced 2025-11-08 18:39:30 +00:00
Don't raise errors when using datetime objects in as_datetime Jinja function/filter (#109062)
* add support for datetime objects to as_datetime * change import of datetime.date --------- Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
committed by
GitHub
parent
3d59303433
commit
e90d76b18d
@@ -1198,6 +1198,35 @@ def test_as_datetime_from_timestamp(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("input", "output"),
|
||||
[
|
||||
(
|
||||
"{% set dt = as_datetime('2024-01-01 16:00:00-08:00') %}",
|
||||
"2024-01-01 16:00:00-08:00",
|
||||
),
|
||||
(
|
||||
"{% set dt = as_datetime('2024-01-29').date() %}",
|
||||
"2024-01-29 00:00:00",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_as_datetime_from_datetime(
|
||||
hass: HomeAssistant, input: str, output: str
|
||||
) -> None:
|
||||
"""Test using datetime.datetime or datetime.date objects as input."""
|
||||
|
||||
assert (
|
||||
template.Template(f"{input}{{{{ dt | as_datetime }}}}", hass).async_render()
|
||||
== output
|
||||
)
|
||||
|
||||
assert (
|
||||
template.Template(f"{input}{{{{ as_datetime(dt) }}}}", hass).async_render()
|
||||
== output
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("input", "default", "output"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user