#35858: Issue with make_aware Function Causing Timezone Conversion Errors
--------------------------------------+--------------------------
               Reporter:  acture      |          Owner:  acture
                   Type:  Bug         |         Status:  assigned
              Component:  Utilities   |        Version:  5.0
               Severity:  Normal      |       Keywords:  timezone
           Triage Stage:  Unreviewed  |      Has patch:  0
    Needs documentation:  0           |    Needs tests:  0
Patch needs improvement:  0           |  Easy pickings:  1
                  UI/UX:  0           |
--------------------------------------+--------------------------
 I have encountered a problem with the make_aware function used in Django
 for converting naive datetime objects to aware datetime objects.

 Steps to Reproduce:
 1. Create a naive datetime object that falls within a DST transition
 period.
 2. Call make_aware with this naive datetime and a timezone that observes
 DST.
 3. Observe the incorrect timezone conversion.

 Code Snippet to reproduce issue
 {{{
 from datetime import datetime
 import pytz
 from django.utils.timezone import make_aware

 time_str = "2024-10-22"
 time_obj = datetime.strptime(time_str, "%Y-%m-%d")
 shanghai_tz = pytz.timezone("Asia/Shanghai")

 pytz_aware_time = shanghai_tz.localize(time_obj)
 django_aware_time = make_aware(time_obj, timezone=shanghai_tz)

 print(f"pytz_aware_time: {pytz_aware_time}")
 print(f"django_aware_time: {django_aware_time}")
 }}}

 Output:
 pytz_aware_time: 2024-10-22 00:00:00+08:00
 django_aware_time: 2024-10-22 00:00:00+08:06


 Environment:
 - Django version: Django 5.0.9
 - Python version: Python 3.12
 - Operating system: macOS Sonoma 14.5
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35858>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070192b2ec0365-10710693-d444-4328-a474-980fa70b88b8-000000%40eu-central-1.amazonses.com.

Reply via email to