Skip to content

fix: adjust Timestamp.astimezone checks #1703

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

Merged
Merged
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
5 changes: 4 additions & 1 deletion interactions/models/discord/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading