MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / fromutc

Method fromutc

tools/python-3.11.9-amd64/Lib/datetime.py:1242–1267  ·  view source on GitHub ↗

datetime in UTC -> datetime in local time.

(self, dt)

Source from the content-addressed store, hash-verified

1240 raise NotImplementedError("tzinfo subclass must override dst()")
1241
1242 def fromutc(self, dt):
1243 "datetime in UTC -> datetime in local time."
1244
1245 if not isinstance(dt, datetime):
1246 raise TypeError("fromutc() requires a datetime argument")
1247 if dt.tzinfo is not self:
1248 raise ValueError("dt.tzinfo is not self")
1249
1250 dtoff = dt.utcoffset()
1251 if dtoff is None:
1252 raise ValueError("fromutc() requires a non-None utcoffset() "
1253 "result")
1254
1255 # See the long comment block at the end of this file for an
1256 # explanation of this algorithm.
1257 dtdst = dt.dst()
1258 if dtdst is None:
1259 raise ValueError("fromutc() requires a non-None dst() result")
1260 delta = dtoff - dtdst
1261 if delta:
1262 dt += delta
1263 dtdst = dt.dst()
1264 if dtdst is None:
1265 raise ValueError("fromutc(): dt.dst gave inconsistent "
1266 "results; cannot convert")
1267 return dt + dtdst
1268
1269 # Pickle support.
1270

Callers 2

_fromtimestampMethod · 0.45
astimezoneMethod · 0.45

Calls 2

utcoffsetMethod · 0.45
dstMethod · 0.45

Tested by

no test coverage detected