MCPcopy Index your code
hub / github.com/python/cpython / dst

Method dst

Lib/test/datetimetester.py:6225–6254  ·  view source on GitHub ↗
(self, dt)

Source from the content-addressed store, hash-verified

6223 return self.stdoffset + self.dst(dt)
6224
6225 def dst(self, dt):
6226 if dt is None or dt.tzinfo is None:
6227 # An exception instead may be sensible here, in one or more of
6228 # the cases.
6229 return ZERO
6230 assert dt.tzinfo is self
6231
6232 # Find first Sunday in April.
6233 start = first_sunday_on_or_after(DSTSTART.replace(year=dt.year))
6234 assert start.weekday() == 6 and start.month == 4 and start.day <= 7
6235
6236 # Find last Sunday in October.
6237 end = first_sunday_on_or_after(DSTEND.replace(year=dt.year))
6238 assert end.weekday() == 6 and end.month == 10 and end.day >= 25
6239
6240 # Can't compare naive to aware objects, so strip the timezone from
6241 # dt first.
6242 dt = dt.replace(tzinfo=None)
6243 if start + HOUR <= dt < end:
6244 # DST is in effect.
6245 return HOUR
6246 elif end <= dt < end + HOUR:
6247 # Fold (an ambiguous hour): use dt.fold to disambiguate.
6248 return ZERO if dt.fold else HOUR
6249 elif start <= dt < start + HOUR:
6250 # Gap (a non-existent hour): reverse the fold rule.
6251 return HOUR if dt.fold else ZERO
6252 else:
6253 # DST is off.
6254 return ZERO
6255
6256Eastern2 = USTimeZone2(-5, "Eastern2", "EST", "EDT")
6257Central2 = USTimeZone2(-6, "Central2", "CST", "CDT")

Callers 2

tznameMethod · 0.95
utcoffsetMethod · 0.95

Calls 3

first_sunday_on_or_afterFunction · 0.70
replaceMethod · 0.45
weekdayMethod · 0.45

Tested by

no test coverage detected