Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#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)

utils_dateformat-r10651.patch (4.2 KB ) - added by George Song 16 years ago.
'U' implementation, tests, and documentation
10825-utils_dateformat-r10651.patch (4.2 KB ) - added by George Song 16 years ago.
Same as last patch, but removed unnecessary self.timezone check
10825.diff (4.5 KB ) - added by Michael Radziej 16 years ago.
patch inluding fix of testcases, replaces older patch

Download all attachments as: .zip

Change History (13)

comment:1 by Alex Gaynor, 16 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:2 by Karen Tracey, 16 years ago

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).

comment:3 by George Song, 16 years ago

Owner: changed from nobody to George Song
Status: newassigned

by George Song, 16 years ago

'U' implementation, tests, and documentation

by George Song, 16 years ago

Same as last patch, but removed unnecessary self.timezone check

comment:4 by George Song, 16 years ago

Has patch: set

Provided patch to let Python do its timezone thing, instead of futzing with offsets, etc.

comment:5 by Matthias Kestenholz, 16 years ago

This patch works for me, thanks.

comment:6 by Michael Radziej, 16 years ago

Owner: changed from George Song to Michael Radziej
Status: assignednew

comment:7 by Michael Radziej, 16 years ago

the patch breaks the dateformat tests. I'm fixing ...

by Michael Radziej, 16 years ago

Attachment: 10825.diff added

patch inluding fix of testcases, replaces older patch

comment:8 by Michael Radziej, 16 years ago

Triage Stage: AcceptedReady 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 Jacob, 16 years ago

Resolution: fixed
Status: newclosed

(In [10716]) Fixed #10825: fixed the 'U' format code to dateformat (and the date/now filter/tag). Thanks to gsong and mir.

comment:10 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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