-
Notifications
You must be signed in to change notification settings - Fork 4.2k
chore: use zoneinfo instead of pytz #37568
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
base: master
Are you sure you want to change the base?
chore: use zoneinfo instead of pytz #37568
Conversation
robrap
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. See comments.
| <%! | ||
| from django.utils.translation import gettext as _ | ||
| from datetime import datetime, timedelta | ||
| import pytz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where datetime is used either, but this is a template, so I don't know if this could be used elsewhere?
- Rather than risk it, it may make sense to leave this in.
- Better yet, you can look back at the history and see where this was added, and if it should have been removed with earlier clean-up, or if it is used in a strange way.
| <%namespace name='static' file='static_content.html'/> | ||
| <%! | ||
| import pytz | ||
| from zoneinfo import ZoneInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- See my other comment about templates. I'd like to ensure that there isn't any danger of removal of pytz. Depending on our findings, we may want to review or test all the
/templates/changes. - Can you move this down to sort it appropriately?
Description
pytz got deprecated in Django 4.0 && has been completely removed in Django 5.0.
Django 4.2 had provided USE_DEPRECATED_PYTZ flag for pytz support which has now been completely removed in Django 5.0 as well.
Django now uses zoneinfo by default and datetime module use this under the hood now instead of pytz
Difference between datetime.timezone and zoneinfo
datetime.timezone and the zoneinfo package are both related to handling time zones in Python, but they serve slightly different purposes and have different use cases.
datetime.timezone
This is part of the standard library in Python.
It provides a simple way to represent a fixed offset from UTC (Coordinated Universal Time).
It doesn't have information about daylight saving time (DST) or historical changes in time zones.
It's suitable for scenarios where you only need to work with a constant offset, and historical changes in time zones are not important.
zoneinfo
The zoneinfo package is introduced in Python 3.9 as part of PEP 615.
It provides a more comprehensive and accurate way to handle time zones by including historical changes, daylight saving time transitions, and more.
It uses the IANA Time Zone Database, which is regularly updated to reflect changes in time zones around the world.
This package is suitable for applications that require precise handling of time zones, especially when dealing with historical dates.
Original Issue link:
#33980
Related PR:
#37148
Since it involves multiple files changes and as suggested in the PR planning to break that PR into multiple small PR.
Smaller PR link: