Skip to content
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

Hard-code settings.TIME_ZONE to UTC #687

Open
jnm opened this issue Mar 10, 2021 · 0 comments
Open

Hard-code settings.TIME_ZONE to UTC #687

jnm opened this issue Mar 10, 2021 · 0 comments

Comments

@jnm
Copy link
Member

jnm commented Mar 10, 2021

We always want to deal with UTC, and we want the UTC offset (+00) to be specified explicitly in the database.

With TIME_ZONE = 'America/New_York, it's easy to mistakenly apply a time zone offset to something that was already UTC. Example:

>>> u.date_joined = datetime.datetime.now()
>>> u.date_joined  # this is already UTC!
datetime.datetime(2021, 3, 10, 22, 42, 55, 843948)
>>> u.save()
>>> u.refresh_from_db()
>>> u.date_joined  # Django assumed it was `America/New_York` and added 5 hours!
datetime.datetime(2021, 3, 11, 3, 42, 55, 843948, tzinfo=<UTC>)

With TIME_ZONE = 'UTC', Django behaves the way we want:

>>> u.date_joined = datetime.datetime.now()
>>> u.date_joined
datetime.datetime(2021, 3, 10, 22, 44, 0, 673962)
>>> u.save()
>>> u.refresh_from_db()
>>> u.date_joined
datetime.datetime(2021, 3, 10, 22, 44, 0, 673962, tzinfo=<UTC>)

Originally posted by @jnm in #677 (comment)

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

No branches or pull requests

1 participant