1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Add UNIX timestamp detection to as_datetime template filter (#60126)

This commit is contained in:
Jan Bouwhuis
2021-11-24 09:51:56 +01:00
committed by GitHub
parent fa0d3a6c48
commit d41d223033
2 changed files with 42 additions and 2 deletions

View File

@@ -732,6 +732,36 @@ def test_as_datetime(hass, input):
)
def test_as_datetime_from_timestamp(hass):
"""Test converting a UNIX timestamp to a date object."""
tests = [
(1469119144, "2016-07-21 16:39:04+00:00"),
(1469119144.0, "2016-07-21 16:39:04+00:00"),
(-1, "1969-12-31 23:59:59+00:00"),
]
for input, output in tests:
# expected = dt_util.parse_datetime(input)
if output is not None:
output = str(output)
assert (
template.Template(f"{{{{ as_datetime({input}) }}}}", hass).async_render()
== output
)
assert (
template.Template(f"{{{{ {input} | as_datetime }}}}", hass).async_render()
== output
)
assert (
template.Template(f"{{{{ as_datetime('{input}') }}}}", hass).async_render()
== output
)
assert (
template.Template(f"{{{{ '{input}' | as_datetime }}}}", hass).async_render()
== output
)
def test_as_local(hass):
"""Test converting time to local."""