diff --git a/homeassistant/components/time_date/sensor.py b/homeassistant/components/time_date/sensor.py index e8e7d38fe35..4615e9e046c 100644 --- a/homeassistant/components/time_date/sensor.py +++ b/homeassistant/components/time_date/sensor.py @@ -96,8 +96,8 @@ class TimeDateSensor(Entity): now = dt_util.utcnow() if self.type == "date": - now = dt_util.start_of_local_day(dt_util.as_local(now)) - return now + timedelta(seconds=86400) + tomorrow = dt_util.as_local(now) + timedelta(days=1) + return dt_util.start_of_local_day(tomorrow) if self.type == "beat": # Add 1 hour because @0 beats is at 23:00:00 UTC. diff --git a/tests/components/time_date/test_sensor.py b/tests/components/time_date/test_sensor.py index 8b8695a2879..b502dad3ea6 100644 --- a/tests/components/time_date/test_sensor.py +++ b/tests/components/time_date/test_sensor.py @@ -137,6 +137,32 @@ async def test_timezone_intervals(hass): next_time = device.get_next_interval() 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( "homeassistant.util.dt.utcnow",