1
0
mirror of https://github.com/django/django.git synced 2025-07-19 09:09:13 +00:00

[1.0.X] Fixed #10048 -- Handle non-existent timezone in dateformat functions.

Backport of r9919 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9920 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2009-02-28 04:52:16 +00:00
parent 106bd0f49e
commit 9b373d0789

View File

@ -131,7 +131,7 @@ class DateFormat(TimeFormat):
def I(self): def I(self):
"'1' if Daylight Savings Time, '0' otherwise." "'1' if Daylight Savings Time, '0' otherwise."
if self.timezone.dst(self.data): if self.timezone and self.timezone.dst(self.data):
return u'1' return u'1'
else: else:
return u'0' return u'0'
@ -192,14 +192,14 @@ class DateFormat(TimeFormat):
def T(self): def T(self):
"Time zone of this machine; e.g. 'EST' or 'MDT'" "Time zone of this machine; e.g. 'EST' or 'MDT'"
name = self.timezone.tzname(self.data) name = self.timezone and self.timezone.tzname(self.data) or None
if name is None: if name is None:
name = self.format('O') name = self.format('O')
return unicode(name) return unicode(name)
def U(self): def U(self):
"Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)" "Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)"
off = self.timezone.utcoffset(self.data) off = self.timezone and self.timezone.utcoffset(self.data) or 0
return int(time.mktime(self.data.timetuple())) + off.seconds * 60 return int(time.mktime(self.data.timetuple())) + off.seconds * 60
def w(self): def w(self):
@ -253,6 +253,8 @@ class DateFormat(TimeFormat):
timezones west of UTC is always negative, and for those east of UTC is timezones west of UTC is always negative, and for those east of UTC is
always positive. always positive.
""" """
if not self.timezone:
return 0
offset = self.timezone.utcoffset(self.data) offset = self.timezone.utcoffset(self.data)
# Only days can be negative, so negative offsets have days=-1 and # Only days can be negative, so negative offsets have days=-1 and
# seconds positive. Positive offsets have days=0 # seconds positive. Positive offsets have days=0