From 0a7b43477b26e433293686dfa8fc756de056e8c0 Mon Sep 17 00:00:00 2001 From: Eman Elsabban Date: Fri, 24 Jan 2025 09:41:43 -0800 Subject: [PATCH] Handling timezone aware jobs --- tron/core/jobrun.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tron/core/jobrun.py b/tron/core/jobrun.py index a89f12bf2..aab5aa1fd 100644 --- a/tron/core/jobrun.py +++ b/tron/core/jobrun.py @@ -119,7 +119,13 @@ def from_json(state_data: str): run_time = datetime.datetime.fromisoformat(raw_run_time) if json_data["time_zone"]: tz = pytz.timezone(json_data["time_zone"]) - run_time = tz.localize(run_time) + if run_time.tzinfo is None: + # if runtime is timezone naive (i.e has no tz information) then localize it + # otherwise we would get a ValueError if we attempt to localize a datetime object that has tz info + run_time = tz.localize(run_time) + else: + # Convert to the desired timezone if it already has timezone information + run_time = run_time.astimezone(tz) else: run_time = None deserialized_data = {