Change output template filters timestamp_local and timestamp_utc to isoformat (#60269)

This commit is contained in:
Jan Bouwhuis 2021-11-24 09:49:03 +01:00 committed by GitHub
parent ed9d40378e
commit fa0d3a6c48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -1462,9 +1462,7 @@ def timestamp_custom(value, date_format=DATE_STR_FORMAT, local=True, default=_SE
def timestamp_local(value, default=_SENTINEL):
"""Filter to convert given timestamp to local date/time."""
try:
return dt_util.as_local(dt_util.utc_from_timestamp(value)).strftime(
DATE_STR_FORMAT
)
return dt_util.as_local(dt_util.utc_from_timestamp(value)).isoformat()
except (ValueError, TypeError):
# If timestamp can't be converted
if default is _SENTINEL:
@ -1476,7 +1474,7 @@ def timestamp_local(value, default=_SENTINEL):
def timestamp_utc(value, default=_SENTINEL):
"""Filter to convert given timestamp to UTC date/time."""
try:
return dt_util.utc_from_timestamp(value).strftime(DATE_STR_FORMAT)
return dt_util.utc_from_timestamp(value).isoformat()
except (ValueError, TypeError):
# If timestamp can't be converted
if default is _SENTINEL:

View File

@ -692,7 +692,7 @@ def test_timestamp_custom(hass):
def test_timestamp_local(hass):
"""Test the timestamps to local filter."""
tests = {None: None, 1469119144: "2016-07-21 16:39:04"}
tests = {None: None, 1469119144: "2016-07-21T16:39:04+00:00"}
for inp, out in tests.items():
assert (
@ -859,8 +859,8 @@ def test_timestamp_utc(hass):
now = dt_util.utcnow()
tests = {
None: None,
1469119144: "2016-07-21 16:39:04",
dt_util.as_timestamp(now): now.strftime("%Y-%m-%d %H:%M:%S"),
1469119144: "2016-07-21T16:39:04+00:00",
dt_util.as_timestamp(now): now.isoformat(),
}
for inp, out in tests.items():