Skip to content

Adding handling for system tz not found exception #1625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions interactions/models/discord/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ def fromtimestamp(cls, t: float, tz=None) -> "Timestamp":
timestamp = super().fromtimestamp(t, tz=tz)
except Exception:
# May be in milliseconds instead of seconds
timestamp = super().fromtimestamp(t / 1000, tz=tz)
t = t / 1000
timestamp = super().fromtimestamp(t, tz=tz)

return timestamp.astimezone() if timestamp.tzinfo is None else timestamp
try:
# Try to fallback to local / system tz
return timestamp.astimezone() if timestamp.tzinfo is None else timestamp
except Exception:
# Fallback to utc tz if no system tz
return super().fromtimestamp(t, tz=timezone.utc)

@classmethod
def fromordinal(cls, n: int) -> "Timestamp":
Expand Down