Skip to content

Commit

Permalink
Merge pull request #1026 from Yelp/u/kkasp/fix-timezones
Browse files Browse the repository at this point in the history
Use localize instead of replace when writing tz info
  • Loading branch information
KaspariK authored Jan 17, 2025
2 parents fccaee3 + 177800a commit 4145c0e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tron/core/jobrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ def to_json(state_data: dict) -> Optional[str]:

@staticmethod
def from_json(state_data: str):
"""Deserialize the JobRun instance to a JSON string."""
"""Deserialize the JobRun instance from a JSON string."""
try:
json_data = json.loads(state_data)
if json_data["run_time"]:
run_time = datetime.datetime.fromisoformat(json_data["run_time"])
raw_run_time = json_data["run_time"]
if raw_run_time:
run_time = datetime.datetime.fromisoformat(raw_run_time)
if json_data["time_zone"]:
run_time = run_time.replace(tzinfo=pytz.timezone(json_data["time_zone"]))
tz = pytz.timezone(json_data["time_zone"])
run_time = tz.localize(run_time)
else:
run_time = None
deserialized_data = {
Expand Down

0 comments on commit 4145c0e

Please sign in to comment.