mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Change output template filters timestamp_local
and timestamp_utc
to isoformat (#60269)
This commit is contained in:
parent
ed9d40378e
commit
fa0d3a6c48
@ -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:
|
||||
|
@ -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():
|
||||
|
Loading…
x
Reference in New Issue
Block a user