Skip to content

Commit

Permalink
Use localize instead of replace when writing tz info
Browse files Browse the repository at this point in the history
  • Loading branch information
KaspariK committed Jan 17, 2025
1 parent fccaee3 commit 6858246
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"])
run_time_str = json_data["run_time"]
if run_time_str:
run_time = datetime.datetime.fromisoformat(run_time_str)
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 6858246

Please sign in to comment.