#35951: Django handling of datetimes in the admin interface can be greatly 
improved
--------------------------------+-----------------------------------------
     Reporter:  Kevin Renskers  |                     Type:  Uncategorized
       Status:  new             |                Component:  Uncategorized
      Version:  5.1             |                 Severity:  Normal
     Keywords:                  |             Triage Stage:  Unreviewed
    Has patch:  0               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+-----------------------------------------
 Some background info first. Here are my Django settings:

 {{{
 USE_I18N = True
 USE_L10N = True
 USE_TZ = True
 TIME_ZONE = "UTC"
 }}}

 And you should know that I am in the Amsterdam timezone, `UTC+1`.

 I don't really understand the way Django handles its `DateTimeField` in
 the admin forms. Like, the warning "Note: You are 1 hour ahead of server
 time." is so incredibly unhelpful. It doesn't make it clear if I should
 enter dates in my local time or in UTC. Why doesn't it just say "Date and
 time are in UTC"? That would make it super clear how I should enter the
 values, which the note does not.

 
[[Image(https://media.hachyderm.io/media_attachments/files/113/560/954/884/415/973/original/2b3c138c50bb1b04.png)]]
 
[[Image(https://media.hachyderm.io/media_attachments/files/113/560/954/883/756/133/original/f56092ca574ff8b5.png)]]

 At the moment I am adding `help_text="Date and time are in UTC"` to all my
 `DateTimeField` instances, and hiding Django's note with the following
 css:

 {{{
 .timezonewarning {
   display: none;
 }
 }}}

 Because our admins just don't know what to enter in these fields with the
 default note.

 And then when these values are shown in the admin interface, it shows them
 in UTC as well, rather than translated to the browser's timezone. Which is
 fine for me, but why? Why even show that warning then? For example, I
 enter `2024-11-28 15:00:00` into one of the my DateTimeFields. This is
 entered as a UTC datetime, right? In the database it's stored as
 `2024-11-28 16:00:00+01`, which is indeed 15:00 in UTC. (Weird that it
 doesn't store it that way, but ok.)

 And then when displaying this value in the admin, it shows `Nov. 28, 2024,
 3 p.m.`. Why does it not show `4 p.m.`, aka my local timezone? Why show
 that weird note about being ahead of server time? And why is the time not
 stored with `+00` in the db?

 Django doesn't know my user's timezone, since this is not something that's
 stored in the `User` model. But, it can use the browser's timezone to show
 these dates and times in the local timezone, right? Or another option: add
 a timezone picker to the top menu, next to the theme switcher for example.

 The [https://docs.djangoproject.com/en/5.1/topics/i18n/timezones/ docs]
 say this:

 > When support for time zones is enabled, Django stores datetime
 information in UTC in the database, uses time-zone-aware datetime objects
 internally, and translates them to the end user’s time zone in templates
 and forms.

 So I guess I just don't really understand the logic behind the timezone
 handling, and why it shows UTC everywhere in the admin.

 Link to Discord thread where it was suggested to create a ticket:
 https://discord.com/channels/856567261900832808/1311696417256898570
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35951>
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 visit 
https://groups.google.com/d/msgid/django-updates/01070193733a040a-872ade0f-e378-45a1-ba8c-11346ecdbec7-000000%40eu-central-1.amazonses.com.

Reply via email to