Skip to content

Conversation

@karolinepauls
Copy link
Collaborator

Using divmod instead of floating point to avoid thinking about precision.

This feature is a trivial convenience that saves on having to check the docs to ensure that datetime.utcfromtimestamp(message.message_timestamp / 1000) is correct code.

Copy link
Collaborator

@LincolnPuzey LincolnPuzey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sensible to me, one comment

integer storing milliseconds.
"""
unix_seconds, ms = divmod(self.message_timestamp, 1000)
return datetime.utcfromtimestamp(unix_seconds).replace(microsecond=ms * 1000, tzinfo=timezone.utc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utcfromtimestamp is deprecated in favor of fromtimestamp

@synweap15
Copy link
Collaborator

Looks good to me

@synweap15 synweap15 merged commit b8967c5 into master Aug 6, 2025
22 checks passed
@LincolnPuzey LincolnPuzey deleted the message-datetime branch August 12, 2025 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants