From 13d2ff216e17047f2da043804e9b9ae4d9e69d18 Mon Sep 17 00:00:00 2001 From: AstreaTSS <25420078+AstreaTSS@users.noreply.github.com> Date: Mon, 17 Jun 2024 18:35:25 -0400 Subject: [PATCH] fix: adjust astimezone checks --- interactions/models/discord/timestamp.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/interactions/models/discord/timestamp.py b/interactions/models/discord/timestamp.py index 2a81e819a..f8d1b81fa 100644 --- a/interactions/models/discord/timestamp.py +++ b/interactions/models/discord/timestamp.py @@ -99,12 +99,15 @@ def astimezone(self, tz: tzinfo | None = None) -> "Timestamp": if self.year > 1970 or (self.year == 1970 and (self.month > 1 or self.day > 1)): return super().astimezone(tz) - if self.year < 1969 or self.month < 12 or self.day < 31: + if self.year < 1969 or (self.year == 1969 and (self.month < 12 or self.day < 31)): # windows kind of breaks down for dates before unix time # technically this is solvable, but it's not worth the effort # also, again, this is a loose bound, but it's good enough for our purposes raise ValueError("astimezone with no arguments is not supported for dates before Unix Time on Windows.") + if tz: + return self.replace(tzinfo=tz) + # to work around the issue to some extent, we'll use a timestamp with a date # that doesn't trigger the bug, and use the timezone from it to modify this # timestamp