issue13666 - Fixing datetime documentation example when using tzinfo

This commit is contained in:
Senthil Kumaran 2012-06-26 20:05:12 +08:00
parent b2ac4d693a
commit 189bd91255
1 changed files with 8 additions and 9 deletions

View File

@ -1093,14 +1093,14 @@ Using datetime with tzinfo:
>>> from datetime import timedelta, datetime, tzinfo >>> from datetime import timedelta, datetime, tzinfo
>>> class GMT1(tzinfo): >>> class GMT1(tzinfo):
... def __init__(self): # DST starts last Sunday in March ... def utcoffset(self, dt):
... return timedelta(hours=1) + self.dst(dt)
... def dst(self, dt):
... # DST starts last Sunday in March
... d = datetime(dt.year, 4, 1) # ends last Sunday in October ... d = datetime(dt.year, 4, 1) # ends last Sunday in October
... self.dston = d - timedelta(days=d.weekday() + 1) ... self.dston = d - timedelta(days=d.weekday() + 1)
... d = datetime(dt.year, 11, 1) ... d = datetime(dt.year, 11, 1)
... self.dstoff = d - timedelta(days=d.weekday() + 1) ... self.dstoff = d - timedelta(days=d.weekday() + 1)
... def utcoffset(self, dt):
... return timedelta(hours=1) + self.dst(dt)
... def dst(self, dt):
... if self.dston <= dt.replace(tzinfo=None) < self.dstoff: ... if self.dston <= dt.replace(tzinfo=None) < self.dstoff:
... return timedelta(hours=1) ... return timedelta(hours=1)
... else: ... else:
@ -1109,16 +1109,15 @@ Using datetime with tzinfo:
... return "GMT +1" ... return "GMT +1"
... ...
>>> class GMT2(tzinfo): >>> class GMT2(tzinfo):
... def __init__(self): ... def utcoffset(self, dt):
... return timedelta(hours=2) + self.dst(dt)
... def dst(self, dt):
... d = datetime(dt.year, 4, 1) ... d = datetime(dt.year, 4, 1)
... self.dston = d - timedelta(days=d.weekday() + 1) ... self.dston = d - timedelta(days=d.weekday() + 1)
... d = datetime(dt.year, 11, 1) ... d = datetime(dt.year, 11, 1)
... self.dstoff = d - timedelta(days=d.weekday() + 1) ... self.dstoff = d - timedelta(days=d.weekday() + 1)
... def utcoffset(self, dt):
... return timedelta(hours=1) + self.dst(dt)
... def dst(self, dt):
... if self.dston <= dt.replace(tzinfo=None) < self.dstoff: ... if self.dston <= dt.replace(tzinfo=None) < self.dstoff:
... return timedelta(hours=2) ... return timedelta(hours=1)
... else: ... else:
... return timedelta(0) ... return timedelta(0)
... def tzname(self,dt): ... def tzname(self,dt):