#21214: Why does Django display all datetimes in UTC by default?
--------------------------------------+---------------------------------
     Reporter:  guillaumechorn@…      |      Owner:  nobody
         Type:  Uncategorized         |     Status:  new
    Component:  Internationalization  |    Version:  1.4
     Severity:  Normal                |   Keywords:  time zone, datetime
 Triage Stage:  Unreviewed            |  Has patch:  0
Easy pickings:  1                     |      UI/UX:  0
--------------------------------------+---------------------------------
 As is mentioned
 [https://docs.djangoproject.com/en/1.4/topics/i18n/timezones/#time-zone-
 aware-input-in-forms here] in the docs, Django has time zone aware input
 in forms, and as a result, PostgreSQL databases store datetime values
 expressed in the time zone of which the form was aware--''not'' UTC.  So
 why then have Django go through the trouble of constantly converting all
 datetime values queried from the database to UTC?  Why not just make the
 developer need to explicitly tell Django (either through a simple setting
 in `settings.py`, or using an optional function in their views) that they
 want values expressed in UTC?

 The issue with having Django automatically convert all datetime values to
 UTC, as is the case now, is that in the case that the developer wants
 datetimes expressed to the user in the same time zone as they were entered
 by the user (which is quite often, I would imagine), they must actually
 write code to convert the values ''back'' to what is already (!) stored in
 the database before rendering them in templates.  I realize that this is
 only strictly the case when using PostgreSQL, but it still makes very
 little sense to me.

 The "Time Zone aware output in templates" referred to
 [https://docs.djangoproject.com/en/1.4/topics/i18n/timezones/#time-zone-
 aware-output-in-templates here] only works in the most basic invocation of
 a datetime value (something like `{{ object.datetime }}`).  It doesn't
 convert the hours if you use something like `{{ object.datetime.hour }}`,
 or the day if you use `{{ object.datetime.day }}`.  I find this extremely
 limited, and quite far removed from Django's usual ability to abstract
 common tasks.  Obviously it's meant to work as an invisible template tag
 that you don't have to type in yourself, and I understand that the same
 template tag wouldn't work for both `{{ object.datetime }}` and `{{
 object.datetime.day }}`. But that's why I think it would make more sense
 for Django to return datetime values as they are formatted in the database
 by default, rather than automatically converting them to UTC (at least
 when usage of PostgreSQL has been declared in `settings.py`).

 Feel free to tell me it's not worth the trouble and I'm being a whiny
 ingrate, but those are my thoughts. =)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/21214>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.e6dad14ddb52386d4a823ea109b32679%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to