Opened 4 years ago

Closed 4 years ago

#19181 closed Uncategorized (invalid)

Document caveats about using DateQuerySet in templates when time zone support is enabled.

Reported by: wiliamsouza83@… Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords: docs
Cc: wiliamsouza83@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Improve the the warning in https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.dates adding a example that when time zone settings.USE_TZ support is enabled and your time zone settings.TIME_ZONE is settled to America / Sao Paulo wich is UTC - 3 in BRT and UTC - 2 in BRST and DateQuerySet return "Oct. 10, 2012, midnight" you will get "Oct. 9, 2012, 9, 00, 00". You should turn off local time when displaying DateQuerySet to avoid problems:

{% load tz %}
{% localtime off %}
{% for month in date_list %}

<p>{{ month }}</p>

{% endfor %}
{% endlocaltime %}

Change History (2)

comment:1 Changed 4 years ago by Aymeric Augustin

I still plan to fix this at some point, see #17260.

comment:2 Changed 4 years ago by Aymeric Augustin

Resolution: invalid
Status: newclosed

Actually, your example still won't display the correct data, because the aggregation was performed in UTC and not in local time in the database.

Generally speaking, I don't want to document workarounds, I want to fix this bug.

Note: See TracTickets for help on using tickets.
Back to Top