Skip to content

DateTimeField uses local time, but stores local time as UTC time #34

@ThinksFast

Description

@ThinksFast

Hi, I'm not sure if this is a django-daisy issue or not, but I suspect it is caused by the datetime picker in the admin UI. Apologies in advance if I'm reporting this to the wrong place. 😄

In my Django app, my app settings specify USE_TZ = True. So all timestamps are recorded as timezone aware and are stored at UTC 0.

Lets say I have a Django model like this:

class BlogPosts(models.Model):
    name = models.CharField(max_length=255)
    publish_date = models.DateTimeField(default=timezone.now)

When I try to edit a data model in Django Admin, I can see these two fields for editing: date and time

Image

When I select a preset like "Now", it enters my local time into the field. This is fine. But when it is stored in the database, it applies UTC 0 timezone to it. So if I am at UTC +1, my local time is 11:59, UTC time is actually 10:59, but the model gets saved at 11:59 UTC 0

To me, this is confusing and makes the presets treacherous to use.

I think this interface would be better for users if the time and date suggestions respected the apps USE_TZ setting. So if USE_TZ = True, then Now would actually say Now (UTC), or something like that, and clicking it would fill in the UTC-adjusted time into the field. The same logic would apply for the date field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions