From 4284deb17a4edeb97cfab998f2151b840719f61a Mon Sep 17 00:00:00 2001 From: JuliusFreudenberger Date: Sat, 10 Jul 2021 23:24:32 +0200 Subject: [PATCH] Improve timezone handling to take DST into account --- marudor_departures.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/marudor_departures.py b/marudor_departures.py index d034a27..84999b1 100644 --- a/marudor_departures.py +++ b/marudor_departures.py @@ -1,6 +1,5 @@ import re -from datetime import timezone, timedelta - +from pytz import timezone import requests from dateutil.parser import parse @@ -69,7 +68,7 @@ def build_reply(departures: list) -> list: reply = [f'Next departures for station: {departures[0]["currentStation"]["title"]}'] for departure in departures: reply_text = f'{departure["train"]["name"]} to "{departure["destination"]}" at ' \ - f'{parse(departure["departure"]["time"]).astimezone(timezone(timedelta(hours=1))).strftime("%H:%M")}' + f'{parse(departure["departure"]["time"]).astimezone(timezone("Europe/Berlin")).strftime("%H:%M")}' if 'delay' in departure['departure']: reply_text += f' (+{str(departure["departure"]["delay"])})'