From 9ca64fa2778e99fce0637a69754b9e4c1ce12540 Mon Sep 17 00:00:00 2001 From: Lev Tolmachev Date: Wed, 14 Dec 2022 10:09:05 +0000 Subject: [PATCH] Fix time_to_station for departed trains API sometimes returns trains that have already departed. In this case timedelta between departure time and now() is negative and as a result timedelta.seconds is ~84600 (full day) Usage of `total_seconds()` fixes this issue because it returns the correct (negative) number of seconds --- custom_components/london_tfl/tfl_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/london_tfl/tfl_data.py b/custom_components/london_tfl/tfl_data.py index 433eb25..7408c9d 100644 --- a/custom_components/london_tfl/tfl_data.py +++ b/custom_components/london_tfl/tfl_data.py @@ -15,7 +15,7 @@ def time_to_station(entry, with_destination=True, style='{0}m {1}s'): next_departure_time = ( parser.parse(entry['expectedArrival']).replace(tzinfo=None) - datetime.utcnow().replace(tzinfo=None) - ).seconds + ).total_seconds() next_departure_dest = get_destination(entry) return style.format( int(next_departure_time / 60),