Open UsamaSadiq opened 10 months ago
We will be doing the Python 3.11 upgrade well before the Django 5.2 upgrade, so I think we can opt for second approach, do this after the Python 3.11 upgrade.
As we are on Python 3.11, this is unblocked now.
https://github.com/search?q=repo%3Aopenedx%2Fedx-platform+country_timezones+language%3APython&type=code There isn't a built-in function for country_timezones in the zoneinfo module. To create a custom one, we would need to hardcode a list of countries and their associated timezones.
Description
pytz
got deprecated in Django 4.0 && has been completely removed in Django 5.0.USE_DEPRECATED_PYTZ
flag forpytz
support which has now been completely removed in Django 5.0 as well.Django
now useszoneinfo
by default anddatetime
module use this under the hood now instead ofpytz
Difference between datetime.timezone and zoneinfo
datetime.timezone
and thezoneinfo
package are both related to handling time zones in Python, but they serve slightly different purposes and have different use cases.datetime.timezone
zoneinfo
zoneinfo
package is introduced inPython 3.9
as part ofPEP 615
.IANA Time Zone
Database, which is regularly updated to reflect changes in time zones around the world.pytz usages to replace
import pytz
→ 268 files inopenedx/edx-platform
.pytz.UTC
→ 97 files inopenedx/edx-platform
.Potential Solution
python<3.9
,Django
providesbackports.zoneinfo
for backward support.datetime
objects created withpytz.UTC
are equivalent to the ones created withZoneInfo("UTC")
- see https://gist.github.com/jwhitlock/08ca74b037c2196f946262ef1a4b775dApproach 01
pytz.UTC
withbackports.zoneinfo.UTC
Python>3.9
backports.zoneinfo
withzoneinfo
Approach 02
Python 3.8
toPython 3.9
pytz.UTC
withzoneinfo.UTC