-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Description
Description
pytzgot deprecated in Django 4.0 && has been completely removed in Django 5.0.- Django 4.2 had provided
USE_DEPRECATED_PYTZflag forpytzsupport which has now been completely removed in Django 5.0 as well. Djangonow useszoneinfoby default anddatetimemodule use this under the hood now instead ofpytz
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
zoneinfopackage is introduced inPython 3.9as part ofPEP 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 ZoneDatabase, 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.
pytz usages to replace
Potential Solution
- For
python<3.9,Djangoprovidesbackports.zoneinfofor backward support. - The timezone-aware
datetimeobjects created withpytz.UTCare equivalent to the ones created withZoneInfo("UTC")- see https://gist.github.com/jwhitlock/08ca74b037c2196f946262ef1a4b775d
Approach 01 (OUTDATED)
- Replace
pytz.UTCwithbackports.zoneinfo.UTC - Migrate to
Python>3.9 - Replace
backports.zoneinfowithzoneinfo
Approach 02
- Upgrade from
Python 3.8toPython 3.9 - Replace
pytz.UTCwithzoneinfo.UTC
Post Django 5.2 update
Edx-platform is already on Django 5.2 and all compatibility issues have already been resolved, even though the platform still relies pytz. Continued work to remove pytz will help remove an unnecessary dependency, following the recommendation in the pytz README:
Projects using Python 3.9 or later should be using the support now included as part of the standard library, and third party packages work with it such as tzdata. pytz offers no advantages beyond backwards compatibility with code written for earlier versions of Python.
Metadata
Metadata
Assignees
Labels
No labels