#10825 closed (fixed)
Template filter date 'U' raises an AttributeError under certain circumstances
| Reported by: | Matthias Kestenholz | Owned by: | Michael Radziej |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Keywords: | template date | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
While fixing #10048 in [9919] a new bug has been introduced. Around line 200 in django/utils/dateformat.py:
def U(self):
"Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)"
off = self.timezone and self.timezone.utcoffset(self.data) or 0
return int(time.mktime(self.data.timetuple())) + off.seconds * 60
If self.timezone and self.timezone.utfoffset(self.data) evaluates to False, Django tries to access off.seconds but off is 0 => An AttributeError (int has no attribute seconds) is raised.
Unfortunately I do not know enough about the timezone handling to provide a test or even a fix.
Attachments (3)
Change History (13)
comment:1 by , 17 years ago
| milestone: | → 1.1 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
comment:3 by , 17 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
by , 17 years ago
| Attachment: | utils_dateformat-r10651.patch added |
|---|
'U' implementation, tests, and documentation
by , 17 years ago
| Attachment: | 10825-utils_dateformat-r10651.patch added |
|---|
Same as last patch, but removed unnecessary self.timezone check
comment:4 by , 17 years ago
| Has patch: | set |
|---|
Provided patch to let Python do its timezone thing, instead of futzing with offsets, etc.
comment:6 by , 17 years ago
| Owner: | changed from to |
|---|---|
| Status: | assigned → new |
by , 17 years ago
| Attachment: | 10825.diff added |
|---|
patch inluding fix of testcases, replaces older patch
comment:8 by , 17 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Fix issues with epoch values in util.datetime.
- fix handling of data without timezone
- fix handling of time zones and DST (you really should not multiply seconds in the first place!)
I double-checked that this now gives correct results with other services on the Internet.
comment:9 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
See also #9850. Note U is documented as "not implemented" and near as I can tell the code before this change didn't work properly either (though I guess perhaps it didn't raise an AttributeError).