diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2012-06-26 12:05:12 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2012-06-26 12:05:12 (GMT) |
commit | 189bd912553798e86f55905713e4ccf6bf323cbe (patch) | |
tree | 3d25e9767669ad3f828c66fe7317aef47c9cf918 | |
parent | b2ac4d693a5571336d397eff93445ca0ac0f4204 (diff) | |
download | cpython-189bd912553798e86f55905713e4ccf6bf323cbe.zip cpython-189bd912553798e86f55905713e4ccf6bf323cbe.tar.gz cpython-189bd912553798e86f55905713e4ccf6bf323cbe.tar.bz2 |
issue13666 - Fixing datetime documentation example when using tzinfo
-rw-r--r-- | Doc/library/datetime.rst | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index 4fc7e9e..2fedef9 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1093,14 +1093,14 @@ Using datetime with tzinfo: >>> from datetime import timedelta, datetime, 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 ... self.dston = d - timedelta(days=d.weekday() + 1) ... d = datetime(dt.year, 11, 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: ... return timedelta(hours=1) ... else: @@ -1109,16 +1109,15 @@ Using datetime with tzinfo: ... return "GMT +1" ... >>> 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) ... self.dston = d - timedelta(days=d.weekday() + 1) ... d = datetime(dt.year, 11, 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: - ... return timedelta(hours=2) + ... return timedelta(hours=1) ... else: ... return timedelta(0) ... def tzname(self,dt): |