Improve timezone handling to take DST into account

This commit is contained in:
JuliusFreudenberger 2021-07-10 23:24:32 +02:00
parent 47b438bd0b
commit 4284deb17a

View file

@ -1,6 +1,5 @@
import re import re
from datetime import timezone, timedelta from pytz import timezone
import requests import requests
from dateutil.parser import parse 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"]}'] reply = [f'Next departures for station: {departures[0]["currentStation"]["title"]}']
for departure in departures: for departure in departures:
reply_text = f'{departure["train"]["name"]} to "{departure["destination"]}" at ' \ 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']: if 'delay' in departure['departure']:
reply_text += f' (+{str(departure["departure"]["delay"])})' reply_text += f' (+{str(departure["departure"]["delay"])})'