Try to work with timezones
All checks were successful
docker-image / docker (push) Successful in 9m54s
All checks were successful
docker-image / docker (push) Successful in 9m54s
This commit is contained in:
parent
87dcc7b360
commit
cc38689bfc
1 changed files with 7 additions and 3 deletions
|
@ -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
|
See also https://github.com/derf/db-fakedisplay/blob/main/README.md
|
||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ from deutschebahn.db_infoscreen import DBInfoscreen
|
||||||
from buba.bubaanimator import BubaAnimation
|
from buba.bubaanimator import BubaAnimation
|
||||||
from buba.bubacmd import BubaCmd
|
from buba.bubacmd import BubaCmd
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
class DBFAnimation(BubaAnimation):
|
class DBFAnimation(BubaAnimation):
|
||||||
def __init__(self, buba: BubaCmd, ds100="AHST", station="Holstenstraße", count=3):
|
def __init__(self, buba: BubaCmd, ds100="AHST", station="Holstenstraße", count=3):
|
||||||
|
@ -43,9 +45,9 @@ class DBFAnimation(BubaAnimation):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def countdown(dt: datetime):
|
def countdown(dt: datetime):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now().astimezone()
|
||||||
try:
|
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:
|
except TypeError as e:
|
||||||
return "--"
|
return "--"
|
||||||
|
|
||||||
|
@ -53,7 +55,9 @@ class DBFAnimation(BubaAnimation):
|
||||||
dep_date = now.date()
|
dep_date = now.date()
|
||||||
|
|
||||||
# Calculate timedelta under the above assumption
|
# 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,
|
# If the calculated timedelta is more than one hour in the past,
|
||||||
# assume that the day should actually be the next day
|
# assume that the day should actually be the next day
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue