#16924 closed Bug (fixed)
'date' template filter displays certain timezones incorrectly
| Reported by: | Drew Roos | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | Normal | Keywords: | template, date, filter, timezone |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | yes | Patch needs improvement: | yes |
| Easy pickings: | yes | UI/UX: | no |
Description
the date template filter will display the wrong timezone offset, if that timezone is a partial-hour offset from UTC, and is west of UTC (negative offset).
>> from django.utils.dateformat import format
>> import pytz
>> from datetime import datetime
>> x = pytz.UTC.localize(datetime(2011, 1, 1)).astimezone(pytz.timezone('America/St_Johns'))
>> format(x, 'O')
u'-0430'
>> y = pytz.UTC.localize(datetime(1970, 1, 1)).astimezone(pytz.timezone('Africa/Monrovia'))
>> format(y, 'O')
u'-0116'
the correct offsets are -0330 and -0044, respectively.
Attachments (1)
Change History (5)
comment:1 by , 14 years ago
| Component: | Template system → Core (Other) |
|---|---|
| Easy pickings: | set |
| Has patch: | unset |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 14 years ago
| Has patch: | set |
|---|
comment:3 by , 14 years ago
| Needs tests: | set |
|---|---|
| Patch needs improvement: | set |
math.copysign makes the code a bit hard to read.
Wouldn't this be more explicit?
sign = '-' if seconds < 0 else '+' seconds = abs(seconds) return '%s%02d%02d" % (sign, seconds // 3600, (seconds // 60) % 60)
This will need a regression test, too.
Note:
See TracTickets
for help on using tickets.
Indeed, the arithmetic at https://code.djangoproject.com/browser/django/trunk/django/utils/dateformat.py#L184
is incorrect for negative values: