-
Notifications
You must be signed in to change notification settings - Fork 4.2k
chore: use zoneinfo instead of pytz #37542
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 #37542
Conversation
| import datetime | ||
| import ddt | ||
| 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.
@ttak-apphelix Optional but can you make the import sorted alphabetically where ever its possible, apply the same to all the occurrences?
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.
updated
| from openedx.core.lib.courses import course_image_url | ||
| from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order | ||
| from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order | ||
| 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.
Sorry, but I just realized that this import was added in a strange place. When imports are split into sections, I think the first is usually from the standard library, the next section (separated by a blank line) are third-party imports, and the final section (also separated by a blank line) are from first-party (or other edx-platform) imports. Does zoneinfo belong at the end of the first group?
If you fix the location of all of these, please do not squash and ensure there is a separate commit, so I can just review that change. Thank you.
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: