datetime in UTC -> datetime in local time.
(self, dt)
| 6486 | EPOCHORDINAL = date(1970, 1, 1).toordinal() |
| 6487 | |
| 6488 | def fromutc(self, dt): |
| 6489 | """datetime in UTC -> datetime in local time.""" |
| 6490 | |
| 6491 | if not isinstance(dt, datetime): |
| 6492 | raise TypeError("fromutc() requires a datetime argument") |
| 6493 | if dt.tzinfo is not self: |
| 6494 | raise ValueError("dt.tzinfo is not self") |
| 6495 | |
| 6496 | timestamp = ((dt.toordinal() - self.EPOCHORDINAL) * 86400 |
| 6497 | + dt.hour * 3600 |
| 6498 | + dt.minute * 60 |
| 6499 | + dt.second) |
| 6500 | |
| 6501 | if timestamp < self.ut[1]: |
| 6502 | tti = self.ti[0] |
| 6503 | fold = 0 |
| 6504 | else: |
| 6505 | idx = bisect.bisect_right(self.ut, timestamp) |
| 6506 | assert self.ut[idx-1] <= timestamp |
| 6507 | assert idx == len(self.ut) or timestamp < self.ut[idx] |
| 6508 | tti_prev, tti = self.ti[idx-2:idx] |
| 6509 | # Detect fold |
| 6510 | shift = tti_prev[0] - tti[0] |
| 6511 | fold = (shift > timedelta(0, timestamp - self.ut[idx-1])) |
| 6512 | dt += tti[0] |
| 6513 | if fold: |
| 6514 | return dt.replace(fold=1) |
| 6515 | else: |
| 6516 | return dt |
| 6517 | |
| 6518 | def _find_ti(self, dt, i): |
| 6519 | timestamp = ((dt.toordinal() - self.EPOCHORDINAL) * 86400 |
nothing calls this directly
no test coverage detected