Skip to content

Commit

Permalink
Fixed #10048 -- Handle non-existent timezone in dateformat functions.
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9919 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Feb 28, 2009
1 parent beb2005 commit b337884
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions django/utils/dateformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def F(self):

def I(self):
"'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'
else:
return u'0'
Expand Down Expand Up @@ -192,14 +192,14 @@ def t(self):

def T(self):
"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:
name = self.format('O')
return unicode(name)

def U(self):
"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

def w(self):
Expand Down Expand Up @@ -253,6 +253,8 @@ def Z(self):
timezones west of UTC is always negative, and for those east of UTC is
always positive.
"""
if not self.timezone:
return 0
offset = self.timezone.utcoffset(self.data)
# Only days can be negative, so negative offsets have days=-1 and
# seconds positive. Positive offsets have days=0
Expand Down

0 comments on commit b337884

Please sign in to comment.