Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72a80e8

Browse files
committed
issue13666 - Fixing datetime documentation example when using tzinfo
1 parent f21804a commit 72a80e8

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

Doc/library/datetime.rst

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,14 +1127,14 @@ Using datetime with tzinfo:
11271127

11281128
>>> from datetime import timedelta, datetime, tzinfo
11291129
>>> class GMT1(tzinfo):
1130-
... def __init__(self): # DST starts last Sunday in March
1130+
... def utcoffset(self, dt):
1131+
... return timedelta(hours=1) + self.dst(dt)
1132+
... def dst(self, dt):
1133+
... # DST starts last Sunday in March
11311134
... d = datetime(dt.year, 4, 1) # ends last Sunday in October
11321135
... self.dston = d - timedelta(days=d.weekday() + 1)
11331136
... d = datetime(dt.year, 11, 1)
11341137
... self.dstoff = d - timedelta(days=d.weekday() + 1)
1135-
... def utcoffset(self, dt):
1136-
... return timedelta(hours=1) + self.dst(dt)
1137-
... def dst(self, dt):
11381138
... if self.dston <= dt.replace(tzinfo=None) < self.dstoff:
11391139
... return timedelta(hours=1)
11401140
... else:
@@ -1143,16 +1143,15 @@ Using datetime with tzinfo:
11431143
... return "GMT +1"
11441144
...
11451145
>>> class GMT2(tzinfo):
1146-
... def __init__(self):
1146+
... def utcoffset(self, dt):
1147+
... return timedelta(hours=2) + self.dst(dt)
1148+
... def dst(self, dt):
11471149
... d = datetime(dt.year, 4, 1)
11481150
... self.dston = d - timedelta(days=d.weekday() + 1)
11491151
... d = datetime(dt.year, 11, 1)
11501152
... self.dstoff = d - timedelta(days=d.weekday() + 1)
1151-
... def utcoffset(self, dt):
1152-
... return timedelta(hours=1) + self.dst(dt)
1153-
... def dst(self, dt):
11541153
... if self.dston <= dt.replace(tzinfo=None) < self.dstoff:
1155-
... return timedelta(hours=2)
1154+
... return timedelta(hours=1)
11561155
... else:
11571156
... return timedelta(0)
11581157
... def tzname(self,dt):
@@ -1545,7 +1544,7 @@ When DST starts (the "start" line), the local wall clock leaps from 1:59 to
15451544
3:00. A wall time of the form 2:MM doesn't really make sense on that day, so
15461545
``astimezone(Eastern)`` won't deliver a result with ``hour == 2`` on the day DST
15471546
begins. In order for :meth:`astimezone` to make this guarantee, the
1548-
:meth:`rzinfo.dst` method must consider times in the "missing hour" (2:MM for
1547+
:meth:`tzinfo.dst` method must consider times in the "missing hour" (2:MM for
15491548
Eastern) to be in daylight time.
15501549

15511550
When DST ends (the "end" line), there's a potentially worse problem: there's an

0 commit comments

Comments
 (0)