mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix time_date interval for DST (#43166)
This commit is contained in:
parent
0a717f313e
commit
55b214ec9c
@ -96,8 +96,8 @@ class TimeDateSensor(Entity):
|
|||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
|
|
||||||
if self.type == "date":
|
if self.type == "date":
|
||||||
now = dt_util.start_of_local_day(dt_util.as_local(now))
|
tomorrow = dt_util.as_local(now) + timedelta(days=1)
|
||||||
return now + timedelta(seconds=86400)
|
return dt_util.start_of_local_day(tomorrow)
|
||||||
|
|
||||||
if self.type == "beat":
|
if self.type == "beat":
|
||||||
# Add 1 hour because @0 beats is at 23:00:00 UTC.
|
# Add 1 hour because @0 beats is at 23:00:00 UTC.
|
||||||
|
@ -137,6 +137,32 @@ async def test_timezone_intervals(hass):
|
|||||||
next_time = device.get_next_interval()
|
next_time = device.get_next_interval()
|
||||||
assert next_time.timestamp() == dt_util.as_timestamp("2017-11-14 00:00:00-07:00")
|
assert next_time.timestamp() == dt_util.as_timestamp("2017-11-14 00:00:00-07:00")
|
||||||
|
|
||||||
|
# Entering DST
|
||||||
|
new_tz = dt_util.get_time_zone("Europe/Prague")
|
||||||
|
assert new_tz is not None
|
||||||
|
dt_util.set_default_time_zone(new_tz)
|
||||||
|
|
||||||
|
now = dt_util.parse_datetime("2020-03-29 00:00+01:00")
|
||||||
|
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||||
|
next_time = device.get_next_interval()
|
||||||
|
assert next_time.timestamp() == dt_util.as_timestamp("2020-03-30 00:00+02:00")
|
||||||
|
|
||||||
|
now = dt_util.parse_datetime("2020-03-29 03:00+02:00")
|
||||||
|
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||||
|
next_time = device.get_next_interval()
|
||||||
|
assert next_time.timestamp() == dt_util.as_timestamp("2020-03-30 00:00+02:00")
|
||||||
|
|
||||||
|
# Leaving DST
|
||||||
|
now = dt_util.parse_datetime("2020-10-25 00:00+02:00")
|
||||||
|
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||||
|
next_time = device.get_next_interval()
|
||||||
|
assert next_time.timestamp() == dt_util.as_timestamp("2020-10-26 00:00:00+01:00")
|
||||||
|
|
||||||
|
now = dt_util.parse_datetime("2020-10-25 23:59+01:00")
|
||||||
|
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||||
|
next_time = device.get_next_interval()
|
||||||
|
assert next_time.timestamp() == dt_util.as_timestamp("2020-10-26 00:00:00+01:00")
|
||||||
|
|
||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
"homeassistant.util.dt.utcnow",
|
"homeassistant.util.dt.utcnow",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user