Skip to content

Use calendar.timegm instead of time.mktime for UTC timestamps #565

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fenuks
Copy link

@fenuks fenuks commented May 8, 2025

time.mktime() converts a time tuple in local time to seconds since the Epoch, as stated in the docs:

Convert a time tuple in local time to seconds since the Epoch.
Note that mktime(gmtime(0)) will not generally return zero for most
time zones; instead the returned value will either be equal to that
of the timezone or altzone attributes on the time module.

calendar.timegm() is guaranteed to produce UTC timestamp:

Unrelated but handy function to calculate Unix timestamp from GMT.

time.mktime() converts a time tuple in local time to seconds since the
Epoch, as stated in the docs:

> Convert a time tuple in local time to seconds since the Epoch.
> Note that mktime(gmtime(0)) will not generally return zero for most
> time zones; instead the returned value will either be equal to that
> of the timezone or altzone attributes on the time module.

calendar.timegm() is guaranteed to produce UTC timestamp:

> Unrelated but handy function to calculate Unix timestamp from GMT.
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.

1 participant