-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Document the "gotcha" behaviors in utcnow() and utcfromtimestamp() #81669
Comments
Between Python 2 and Python 3, the meaning of a naive datetime underwent a subtle change. Previously a naive datetime was mostly treated as an abstract datetime in the same way a unitless number is treated as an abstract quantity (this is reflected in the current datetime documentation). In Python 3, though, it became more concrete in the sense that rather than just throwing an error whenever you try to do an operation that requires knowing the absolute datetime (e.g. convert between time zones, convert to timestamp, etc), certain operations will succeed with the assumption that naive times represent system local times. This makes For example, see this script, executed this with >>> from datetime import datetime
>>> dt = datetime.utcfromtimestamp(0)
>>> dt
datetime.datetime(1970, 1, 1, 0, 0)
>>> dt.timestamp()
18000 This happens because EST is 18000s behind UTC, and I'm not sure if actually deprecating |
Why not deprecate them? |
Thanks Joannah! |
utcnow is deprecated and should not be used anymore. this commit swap utcnow() by now(timezone.utc) see: python/cpython#103857 python/cpython#81669 python 3.12 changes related to this: https://docs.python.org/3/whatsnew/3.12.html#deprecated task-3932942
utcnow is deprecated and should not be used anymore. this commit swap utcnow() by now(timezone.utc) see: python/cpython#103857 python/cpython#81669 python 3.12 changes related to this: https://docs.python.org/3/whatsnew/3.12.html#deprecated task-3932942 closes #165799 Signed-off-by: Bertrand Dossogne (bedo) <bedo@odoo.com>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: