This is called from the default datetime.astimezone() implementation. When called from that, dt.tzinfo is self, and dt’s date and time data are to be viewed as expressing a UTC time. The purpose of fromutc() is to adjust the date and time data, returning an equivalent datetime in self’s local time.
tzinfo.fromutc(dt)
def fromutc(self, dt):
raise ValueError error if dt.tzinfo is not self
dtoff = dt.utcoffset()
dtdst = dt.dst()
raise ValueError if dtoff is None or dtdst is None
delta = dtoff - dtdst this is self's standard offset
if delta:
dt += delta convert to standard local time
dtdst = dt.dst()
raise ValueError if dtdst is None
if dtdst:
return dt + dtdst
else:
return dt