Opened 16 years ago
Closed 9 years ago
#11321 closed Bug (fixed)
Bug with humanize and timezones
Reported by: | aarond10 | Owned by: | nobody |
---|---|---|---|
Component: | contrib.humanize | Version: | dev |
Severity: | Normal | Keywords: | humanize, naturalday, timezone |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | yes |
Description
Humanize's naturalday filter uses "date.today()" to determine relative dates. This is not valid if you pass it a datetime with the tzinfo field set. The following patch uses a datetime object as an intermediary to correct this behavior.
Attachments (5)
Change History (13)
by , 16 years ago
Attachment: | humanize_patch.txt added |
---|
comment:1 by , 16 years ago
milestone: | 1.1 |
---|---|
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
This is annoying, but it isn't critical for v1.1 at this late stage (it doesn't cause data loss, and there are viable workarounds).
Also, the patch needs tests in order to prove that it works.
comment:2 by , 16 years ago
Very basic test cases:
from django.contrib.humanize.templatetags.humanize import naturalday
from datetime import datetime
from pytz import timezone
# Test without timezone (basically the same as existing code)
naturalday(datetime.now())
u'today'
# GMT+9
naturalday(datetime.now(timezone('Asia/Tokyo')))
u'today'
# GMT+2
naturalday(datetime.now(timezone('Europe/Rome')))
u'today'
# GMT+0
naturalday(datetime.now(timezone('UTC')))
u'today'
# GMT-4
naturalday(datetime.now(timezone('America/New_York')))
u'today'
by , 15 years ago
Attachment: | 11321-r11173.2.diff added |
---|
comment:3 by , 14 years ago
Needs documentation: | set |
---|---|
Needs tests: | unset |
comment:4 by , 14 years ago
Component: | Contrib apps → contrib.humanize |
---|
comment:5 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:7 by , 9 years ago
Easy pickings: | set |
---|---|
Resolution: | fixed |
Status: | closed → new |
UI/UX: | set |
To be honoust I still don't like the solution.
It means you have to create a custom Date object (that inherits from datetime.date), where you manually set the tzinfo attribute.
I think using timezone.get_current_timezone() would be much more convenient!
comment:8 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This ticket was closed 5 years ago, before Django gained support for timezones in version 1.4. The naturalday filter was refactored in that version.
Given that the landscape has changed significantly since this ticket was discussed, it would be best to open a new ticket and explain the problem you see in the current implementation.
That will make it more likely that someone will understand what you want to do and make it happen. Thanks!
Patch to humanize.py