Make uk_transport sensor timezone/DST aware (#26577)

* Make uk_transport sensor timezone/DST aware

* Fix offset-naive and offset-aware datetime comparison
pull/26587/head
Tsvi Mostovicz 2019-09-11 17:37:09 +03:00 committed by Martin Hjelmare
parent faeb95581a
commit f53fcacf49
1 changed files with 4 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import requests
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
import homeassistant.util.dt as dt_util
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_MODE
from homeassistant.helpers.entity import Entity
@ -277,12 +278,11 @@ class UkTransportLiveTrainTimeSensor(UkTransportSensor):
def _delta_mins(hhmm_time_str):
"""Calculate time delta in minutes to a time in hh:mm format."""
now = datetime.now()
now = dt_util.now()
hhmm_time = datetime.strptime(hhmm_time_str, "%H:%M")
hhmm_datetime = datetime(
now.year, now.month, now.day, hour=hhmm_time.hour, minute=hhmm_time.minute
)
hhmm_datetime = now.replace(hour=hhmm_time.hour, minute=hhmm_time.minute)
if hhmm_datetime < now:
hhmm_datetime += timedelta(days=1)