Skip to content

Commit

Permalink
fix: don't create a datetime without a timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycojoker committed Jan 17, 2025
1 parent 88177b1 commit 6e8c6b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/aleph_client/commands/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def _show_compute(node_info):
node_hash = node["hash"]

# Format Value
creation_time = datetime.datetime.fromtimestamp(node["time"]).strftime("%Y-%m-%d %H:%M:%S")
creation_time = datetime.datetime.fromtimestamp(node["time"], tz=datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
score = _format_score(node["score"])
decentralization = _format_score(node["decentralization"])
status = _format_status(node["status"])
Expand Down Expand Up @@ -131,7 +133,9 @@ def _show_core(node_info):
node_name = _remove_ansi_escape(node_name)

# Format Value
creation_time = datetime.datetime.fromtimestamp(node["time"]).strftime("%Y-%m-%d %H:%M:%S")
creation_time = datetime.datetime.fromtimestamp(node["time"], tz=datetime.timezone.utc).strftime(
"%Y-%m-%d %H:%M:%S"
)
score = _format_score(node["score"])
status = _format_status(node["status"])

Expand Down
4 changes: 2 additions & 2 deletions src/aleph_client/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import os
import sys
from datetime import datetime
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, Callable, TypeVar

Expand Down Expand Up @@ -160,7 +160,7 @@ def str_to_datetime(date: str | None) -> datetime | None:
return None
try:
date_f = float(date)
return datetime.fromtimestamp(date_f)
return datetime.fromtimestamp(date_f, tz=timezone.utc)
except ValueError:
pass
return datetime.fromisoformat(date)
Expand Down

0 comments on commit 6e8c6b7

Please sign in to comment.