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

Method fromutc

Lib/_pydatetime.py:1330–1355  ·  view source on GitHub ↗

datetime in UTC -> datetime in local time.

(self, dt)

Source from the content-addressed store, hash-verified

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

Callers 2

_fromtimestampMethod · 0.45
astimezoneMethod · 0.45

Calls 2

utcoffsetMethod · 0.45
dstMethod · 0.45

Tested by

no test coverage detected