The tzinfo methods utcoffset() and dst() must return a timedelta object

(or None) now.  In 2.3a1 they could also return an int or long, but that
was an unhelpfully redundant leftover from an earlier version wherein
they couldn't return a timedelta.  TOOWTDI.
This commit is contained in:
Tim Peters 2003-01-02 21:28:08 +00:00
parent 4abd5f0fce
commit 397301eccb
5 changed files with 84 additions and 77 deletions

View file

@ -1,16 +1,18 @@
from datetime import tzinfo
from datetime import tzinfo, timedelta
ZERO = timedelta(0)
class UTC(tzinfo):
"""UTC"""
def utcoffset(self, dt):
return 0
return ZERO
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return 0
return ZERO
class FixedOffset(tzinfo):
"""Fixed offset in minutes east from UTC."""
@ -26,8 +28,7 @@ class FixedOffset(tzinfo):
return self.__name
def dst(self, dt):
# It depends on more than we know in an example.
return None # Indicate we don't know
return ZERO
import time
@ -43,9 +44,9 @@ class LocalTime(tzinfo):
def utcoffset(self, dt):
if self._isdst(dt):
return -time.timezone/60
return timedelta(seconds=-time.timezone)
else:
return -time.altzone/60
return timedelta(seconds=-time.altzone)
def tzname(self, dt):
return time.tzname[self._isdst(dt)]