@@ -30,7 +30,7 @@ \section{\module{datetime} ---
3030
3131For applications requiring more, \class {datetime} and \class {time}
3232objects have an optional time zone information member,
33- \member {tzinfo}, that can contain an instance of a subclass of
33+ \member {tzinfo}, that can contain an instance of a subclass of
3434the abstract \class {tzinfo} class. These \class {tzinfo} objects
3535capture information about the offset from UTC time, the time zone
3636name, and whether Daylight Saving Time is in effect. Note that no
@@ -1048,8 +1048,10 @@ \subsection{\class{tzinfo} Objects \label{datetime-tzinfo}}
10481048
10491049 If \method {utcoffset()} does not return \code {None},
10501050 \method {dst()} should not return \code {None} either.
1051- \end {methoddesc }
10521051
1052+ The default implementation of \method {utcoffset()} raises
1053+ \exception {NotImplementedError}.
1054+ \end {methoddesc }
10531055
10541056\begin {methoddesc }{dst}{self, dt}
10551057 Return the daylight saving time (DST) adjustment, in minutes east of
@@ -1060,7 +1062,7 @@ \subsection{\class{tzinfo} Objects \label{datetime-tzinfo}}
10601062 Note that DST offset, if applicable, has
10611063 already been added to the UTC offset returned by
10621064 \method {utcoffset()}, so there's no need to consult \method {dst()}
1063- unless you're interested in displaying DST info separately. For
1065+ unless you're interested in obtaining DST info separately. For
10641066 example, \method {datetime.timetuple()} calls its \member {tzinfo}
10651067 member's \method {dst()} method to determine how the
10661068 \member {tm_isdst} flag should be set, and
@@ -1080,6 +1082,10 @@ \subsection{\class{tzinfo} Objects \label{datetime-tzinfo}}
10801082 cannot detect violations; it's the programmer's responsibility to
10811083 ensure it.
10821084
1085+ The default implementation of \method {dst()} raises
1086+ \exception {NotImplementedError}.
1087+ \end {methoddesc }
1088+
10831089\begin {methoddesc }{tzname}{self, dt}
10841090 Return the timezone name corresponding to the \class {datetime}
10851091 object represented
@@ -1092,8 +1098,9 @@ \subsection{\class{tzinfo} Objects \label{datetime-tzinfo}}
10921098 will wish to return different names depending on the specific value
10931099 of \var {dt} passed, especially if the \class {tzinfo} class is
10941100 accounting for daylight time.
1095- \end {methoddesc }
10961101
1102+ The default implementation of \method {tzname()} raises
1103+ \exception {NotImplementedError}.
10971104\end {methoddesc }
10981105
10991106These methods are called by a \class {datetime} or \class {time} object,
@@ -1106,21 +1113,23 @@ \subsection{\class{tzinfo} Objects \label{datetime-tzinfo}}
11061113When \code {None} is passed, it's up to the class designer to decide the
11071114best response. For example, returning \code {None} is appropriate if the
11081115class wishes to say that time objects don't participate in the
1109- \class {tzinfo} protocol. In other applications, it may be more useful
1110- for \code {utcoffset(None)} to return the standard UTC offset.
1116+ \class {tzinfo} protocol. It may be more useful for \code {utcoffset(None)}
1117+ to return the standard UTC offset, as there is no other convention for
1118+ discovering the standard offset.
11111119
11121120When a \class {datetime} object is passed in response to a
11131121\class {datetime} method, \code {dt.tzinfo} is the same object as
11141122\var {self}. \class {tzinfo} methods can rely on this, unless
11151123user code calls \class {tzinfo} methods directly. The intent is that
11161124the \class {tzinfo} methods interpret \var {dt} as being in local time,
1117- and not need to worry about objects in other timezones.
1125+ and not need worry about objects in other timezones.
11181126
11191127Example \class {tzinfo} classes:
11201128
11211129\verbatiminput {tzinfo-examples.py}
11221130
1123- Note that there are unavoidable subtleties twice per year in a tzinfo
1131+ Note that there are unavoidable subtleties twice per year in a
1132+ \class {tzinfo}
11241133subclass accounting for both standard and daylight time, at the DST
11251134transition points. For concreteness, consider US Eastern (UTC -0500),
11261135where EDT begins the minute after 1:59 (EST) on the first Sunday in
@@ -1140,32 +1149,29 @@ \subsection{\class{tzinfo} Objects \label{datetime-tzinfo}}
11401149to 3:00. A wall time of the form 2:MM doesn't really make sense on that
11411150day, so \code {astimezone(Eastern)} won't deliver a result with
11421151\code {hour==2} on the
1143- day DST begins. How an Eastern instance chooses to interpret 2:MM on
1144- that day is its business. The example Eastern implementation above
1145- chose to
1146- consider it as a time in EDT, simply because it "looks like it's
1147- after 2:00", and so synonymous with the EST 1:MM times on that day.
1148- Your Eastern class may wish, for example, to raise an exception instead
1149- when it sees a 2:MM time on the day EDT begins.
1152+ day DST begins. In order for \method {astimezone()} to make this
1153+ guarantee, the \class {tzinfo} \method {dst()} method must consider times
1154+ in the "missing hour" (2:MM for Eastern) to be in daylight time.
11501155
11511156When DST ends (the "end" line), there's a potentially worse problem:
1152- there's an hour that can't be spelled unambiguously in local wall time, the
1153- hour beginning at the moment DST ends . In this example , that's times of
1154- the form 6 :MM UTC on the day daylight time ends. The local wall clock
1157+ there's an hour that can't be spelled unambiguously in local wall time:
1158+ the last hour of daylight time . In Eastern , that's times of
1159+ the form 5 :MM UTC on the day daylight time ends. The local wall clock
11551160leaps from 1:59 (daylight time) back to 1:00 (standard time) again.
1156- 1:MM is taken as daylight time (it's "before 2:00" ), so maps to 5:MM UTC.
1157- 2:MM is taken as standard time (it's "after 2:00" ), so maps to 7:MM UTC.
1158- There is no local time that maps to 6:MM UTC on this day.
1159-
1160- Just as the wall clock does, \code {astimezone(Eastern)} maps both UTC
1161- hours 5:MM
1162- and 6:MM to Eastern hour 1:MM on this day. However, this result is
1163- ambiguous (there's no way for Eastern to know which repetition of 1:MM
1164- is intended). Applications that can't bear such ambiguity
1165- should avoid using hybrid tzinfo classes; there are no
1166- ambiguities when using UTC, or any other fixed-offset tzinfo subclass
1167- (such as a class representing only EST (fixed offset -5 hours), or only
1168- EDT (fixed offset -4 hours)).
1161+ Local times of the form 1:MM are ambiguous. \method {astimezone()} mimics
1162+ the local clock's behavior by mapping two adjacent UTC hours into the
1163+ same local hour then. In the Eastern example, UTC times of the form
1164+ 5:MM and 6:MM both map to 1:MM when converted to Eastern. In order for
1165+ \method {astimezone()} to make this guarantee, the \class {tzinfo}
1166+ \method {dst()} method must consider times in the "repeated hour" to be in
1167+ standard time. This is easily arranged, as in the example, by expressing
1168+ DST switch times in the time zone's standard local time.
1169+
1170+ Applications that can't bear such ambiguities should avoid using hybrid
1171+ \class {tzinfo} subclasses; there are no ambiguities when using UTC, or
1172+ any other fixed-offset \class {tzinfo} subclass (such as a class
1173+ representing only EST (fixed offset -5 hours), or only EDT (fixed offset
1174+ -4 hours)).
11691175
11701176
11711177\subsection {\method {strftime()} Behavior }
0 commit comments