From 1819c0290ccd1e063886a880c4afdd034e36784a Mon Sep 17 00:00:00 2001 From: DrosoCode Date: Thu, 22 Sep 2022 19:01:40 +0200 Subject: [PATCH] fix timezone --- idfm_api/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/idfm_api/models.py b/idfm_api/models.py index c75b159..ad495ba 100644 --- a/idfm_api/models.py +++ b/idfm_api/models.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from datetime import datetime +from datetime import datetime, timezone from functools import total_ordering from enum import Enum, unique @@ -65,8 +65,8 @@ def from_json(data: dict): name=name, id=data.get("id"), message=message, - start_time=datetime.strptime(data.get("RecordedAtTime"), '%Y-%m-%dT%H:%M:%S.%fZ'), - end_time=datetime.strptime(data.get("ValidUntilTime"), '%Y-%m-%dT%H:%M:%S.%fZ'), + start_time=datetime.strptime(data.get("RecordedAtTime"), '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=timezone.utc), + end_time=datetime.strptime(data.get("ValidUntilTime"), '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=timezone.utc), type=data["InfoChannelRef"]["value"], severity=data.get("InfoMessageVersion") ) @@ -99,9 +99,9 @@ def from_json(data: dict): sch = None if "ExpectedArrivalTime" in data["MonitoredVehicleJourney"]["MonitoredCall"]: - sch = datetime.strptime(data["MonitoredVehicleJourney"]["MonitoredCall"]["ExpectedArrivalTime"], '%Y-%m-%dT%H:%M:%S.%fZ') + sch = datetime.strptime(data["MonitoredVehicleJourney"]["MonitoredCall"]["ExpectedArrivalTime"], '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=timezone.utc) elif "ExpectedDepartureTime" in data["MonitoredVehicleJourney"]["MonitoredCall"]: - sch = datetime.strptime(data["MonitoredVehicleJourney"]["MonitoredCall"]["ExpectedDepartureTime"], '%Y-%m-%dT%H:%M:%S.%fZ') + sch = datetime.strptime(data["MonitoredVehicleJourney"]["MonitoredCall"]["ExpectedDepartureTime"], '%Y-%m-%dT%H:%M:%S.%fZ').replace(tzinfo=timezone.utc) else: return None