From cc38689bfc31b0ebc6d2caf33114edddbbaad207 Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Tue, 10 Jun 2025 22:22:56 +0200 Subject: [PATCH] Try to work with timezones --- buba/animations/dbf.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/buba/animations/dbf.py b/buba/animations/dbf.py index 9c32980..8db52d2 100644 --- a/buba/animations/dbf.py +++ b/buba/animations/dbf.py @@ -4,6 +4,7 @@ Pull departure info from https://trains.xatlabs.com and display. See also https://github.com/derf/db-fakedisplay/blob/main/README.md """ import datetime +import logging from threading import Thread from time import sleep @@ -12,6 +13,7 @@ from deutschebahn.db_infoscreen import DBInfoscreen from buba.bubaanimator import BubaAnimation from buba.bubacmd import BubaCmd +LOG = logging.getLogger(__name__) class DBFAnimation(BubaAnimation): def __init__(self, buba: BubaCmd, ds100="AHST", station="Holstenstraße", count=3): @@ -43,9 +45,9 @@ class DBFAnimation(BubaAnimation): @staticmethod def countdown(dt: datetime): - now = datetime.datetime.now() + now = datetime.datetime.now().astimezone() try: - dep_time = datetime.datetime.strptime(dt, "%H:%M").time() + dep_time = datetime.datetime.strptime(dt, "%H:%M").replace(tzinfo=now.tzinfo).time() except TypeError as e: return "--" @@ -53,7 +55,9 @@ class DBFAnimation(BubaAnimation): dep_date = now.date() # Calculate timedelta under the above assumption - dep_td = datetime.datetime.combine(dep_date, dep_time) - now + dep_td = datetime.datetime.combine(dep_date, dep_time,tzinfo=now.tzinfo) - now + + LOG.info(f"Processing time {datetime.datetime.combine(dep_date, dep_time, tzinfo=now.tzinfo)}, delta {dep_td}") # If the calculated timedelta is more than one hour in the past, # assume that the day should actually be the next day