From 2de31224a79477d3f4ab3a0c9128088d9db7debb Mon Sep 17 00:00:00 2001 From: AutonomousCat <130127508+AutonomousCat@users.noreply.github.com> Date: Thu, 7 Mar 2024 05:29:27 -0800 Subject: [PATCH 1/2] Update timestamp.py --- interactions/models/discord/timestamp.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/interactions/models/discord/timestamp.py b/interactions/models/discord/timestamp.py index 57a6e4dd7..d0f9486db 100644 --- a/interactions/models/discord/timestamp.py +++ b/interactions/models/discord/timestamp.py @@ -62,7 +62,12 @@ def fromtimestamp(cls, t: float, tz=None) -> "Timestamp": # May be in milliseconds instead of seconds timestamp = super().fromtimestamp(t / 1000, 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 timezone if system tz not found + return super().fromtimestamp(t / 1000, tz=timezone.utc) @classmethod def fromordinal(cls, n: int) -> "Timestamp": From 69a91a8c60f375c1f7da9561d69c13071c8d3b72 Mon Sep 17 00:00:00 2001 From: AutonomousCat <130127508+AutonomousCat@users.noreply.github.com> Date: Thu, 7 Mar 2024 05:36:34 -0800 Subject: [PATCH 2/2] Update timestamp.py --- interactions/models/discord/timestamp.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/interactions/models/discord/timestamp.py b/interactions/models/discord/timestamp.py index d0f9486db..8114d8385 100644 --- a/interactions/models/discord/timestamp.py +++ b/interactions/models/discord/timestamp.py @@ -60,14 +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) try: # Try to fallback to local / system tz return timestamp.astimezone() if timestamp.tzinfo is None else timestamp except Exception: - # Fallback to utc timezone if system tz not found - return super().fromtimestamp(t / 1000, tz=timezone.utc) + # Fallback to utc tz if no system tz + return super().fromtimestamp(t, tz=timezone.utc) @classmethod def fromordinal(cls, n: int) -> "Timestamp":