Skip to content

Commit

Permalink
Merge pull request #1027 from Yelp/u/emanelsabban/TRON-2354
Browse files Browse the repository at this point in the history
Handling timezone aware jobs
  • Loading branch information
EmanElsaban authored Jan 24, 2025
2 parents b4d3422 + 0a7b434 commit 6dd708a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tron/core/jobrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 6dd708a

Please sign in to comment.