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

Class tzinfo

Lib/_pydatetime.py:1307–1365  ·  view source on GitHub ↗

Abstract base class for time zone info objects. Subclasses must override the tzname(), utcoffset() and dst() methods.

Source from the content-addressed store, hash-verified

1305
1306
1307class tzinfo:
1308 """Abstract base class for time zone info objects.
1309
1310 Subclasses must override the tzname(), utcoffset() and dst() methods.
1311 """
1312 __slots__ = ()
1313
1314 def tzname(self, dt):
1315 "datetime -> string name of time zone."
1316 raise NotImplementedError("tzinfo subclass must override tzname()")
1317
1318 def utcoffset(self, dt):
1319 "datetime -> timedelta, positive for east of UTC, negative for west of UTC"
1320 raise NotImplementedError("tzinfo subclass must override utcoffset()")
1321
1322 def dst(self, dt):
1323 """datetime -> DST offset as timedelta, positive for east of UTC.
1324
1325 Return 0 if DST not in effect. utcoffset() must include the DST
1326 offset.
1327 """
1328 raise NotImplementedError("tzinfo subclass must override dst()")
1329
1330 def fromutc(self, dt):
1331 "datetime in UTC -> datetime in local time."
1332
1333 if not isinstance(dt, datetime):
1334 raise TypeError("fromutc() requires a datetime argument")
1335 if dt.tzinfo is not self:
1336 raise ValueError("dt.tzinfo is not self")
1337
1338 dtoff = dt.utcoffset()
1339 if dtoff is None:
1340 raise ValueError("fromutc() requires a non-None utcoffset() "
1341 "result")
1342
1343 # See the long comment block at the end of this file for an
1344 # explanation of this algorithm.
1345 dtdst = dt.dst()
1346 if dtdst is None:
1347 raise ValueError("fromutc() requires a non-None dst() result")
1348 delta = dtoff - dtdst
1349 if delta:
1350 dt += delta
1351 dtdst = dt.dst()
1352 if dtdst is None:
1353 raise ValueError("fromutc(): dt.dst gave inconsistent "
1354 "results; cannot convert")
1355 return dt + dtdst
1356
1357 # Pickle support.
1358
1359 def __reduce__(self):
1360 getinitargs = getattr(self, "__getinitargs__", None)
1361 if getinitargs:
1362 args = getinitargs()
1363 else:
1364 args = ()

Callers 4

test_non_abstractnessMethod · 0.90
test_extra_attributesMethod · 0.90
test_check_tzinfoMethod · 0.90

Calls

no outgoing calls

Tested by 4

test_non_abstractnessMethod · 0.72
test_extra_attributesMethod · 0.72
test_check_tzinfoMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…