#35858: Issue with make_aware Function Causing Timezone Conversion Errors with pytz
---------------------------+--------------------------------------
Reporter: acture | Owner: acture
Type: Bug | Status: closed
Component: Utilities | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: timezone | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+--------------------------------------
Comment (by acture):
I believe adding a warning is still necessary.
It could can help developers recognize that pytz is no longer recommended,
and understand the potential risks of continuing to use pytz.
Not all developers stay up-to-date with the latest changes in Django. Some
developers might not even be aware that zoneinfo has replaced pytz as the
default timezone implementation. A warning would serve as an educational
tool, ensuring that both new and experienced developers understand this
shift.
Without a clear warning, developers might continue using pytz simply
because it's familiar, not knowing that Django has moved on to zoneinfo. A
warning helps inform them of best practices moving forward. By adding a
warning, we can prompt developers to test and verify that their timezone-
related logic behaves as expected
Replying to [comment:1 Sarah Boyce]:
> Since Django 4.0, [
https://docs.djangoproject.com/en/5.1/releases/4.0
/#zoneinfo-default-timezone-implementation zoneinfo is the default
timezone implementation].
> I believe you shouldn't be using pytz here
> {{{#!python
> from datetime import datetime
> from django.utils.timezone import make_aware
> from zoneinfo import ZoneInfo
>
> time_str = "2024-10-22"
> time_obj = datetime.strptime(time_str, "%Y-%m-%d")
> shanghai_tz = ZoneInfo("Asia/Shanghai")
>
> django_aware_time = make_aware(time_obj, timezone=shanghai_tz)
> print(f"django_aware_time: {django_aware_time}")
> }}}
> Returns `django_aware_time: 2024-10-22 00:00:00+08:00`
--
Ticket URL: <
https://code.djangoproject.com/ticket/35858#comment:2>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.