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:
@@ -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."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user