Opened 4 years ago

Closed 4 years ago

#17343 closed Bug (fixed)

The {% now %} template tag does not use time zones

Reported by: oinopion Owned by: aaugustin
Component: Template system Version: master
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Current django-trunk now tag uses datatime.now() instead of timezone.now().
I've made patch to fix that, but I'd really like to have some help with writing test.

Here's my fork over on github:
https://github.com/oinopion/django/commit/aad87fdd8cbdd02dd949da355efc4b7f127848a3

Attachments (1)

tz.diff (2.5 KB) - added by oinopion 4 years ago.
Consolidated diff

Download all attachments as: .zip

Change History (5)

comment:1 Changed 4 years ago by oinopion

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

To clarify the issue:

Dates that are coming from Django (when using USE_TZ = True) should be presented in users current time zone.

That means this should true (regardless of time zone used):

with timezone.override('Europe/Warsaw'):
    assert Template('{% now "H:i:s" %}').render(Context()) == timezone.localtime(timezone.now()).strftime('%H:%M:%S')

Currently user is presented with date localized to default time zone.

Last edited 4 years ago by oinopion (previous) (diff)

comment:2 Changed 4 years ago by aaugustin

  • Easy pickings set
  • Needs tests set
  • Owner changed from nobody to aaugustin
  • Severity changed from Normal to Release blocker
  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by oinopion

Consolidated diff

comment:4 Changed 4 years ago by aaugustin

  • Resolution set to fixed
  • Status changed from new to closed

In [17169]:

Fixed #17343 -- Changed the {% now %} tag to use the current time zone when time zone support is enabled. Thanks oinopion for the report.

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