datetime in UTC -> datetime in local time.
(self, dt)
| 6171 | class tzinfo2(tzinfo): |
| 6172 | |
| 6173 | def fromutc(self, dt): |
| 6174 | "datetime in UTC -> datetime in local time." |
| 6175 | |
| 6176 | if not isinstance(dt, datetime): |
| 6177 | raise TypeError("fromutc() requires a datetime argument") |
| 6178 | if dt.tzinfo is not self: |
| 6179 | raise ValueError("dt.tzinfo is not self") |
| 6180 | # Returned value satisfies |
| 6181 | # dt + ldt.utcoffset() = ldt |
| 6182 | off0 = dt.replace(fold=0).utcoffset() |
| 6183 | off1 = dt.replace(fold=1).utcoffset() |
| 6184 | if off0 is None or off1 is None or dt.dst() is None: |
| 6185 | raise ValueError |
| 6186 | if off0 == off1: |
| 6187 | ldt = dt + off0 |
| 6188 | off1 = ldt.utcoffset() |
| 6189 | if off0 == off1: |
| 6190 | return ldt |
| 6191 | # Now, we discovered both possible offsets, so |
| 6192 | # we can just try four possible solutions: |
| 6193 | for off in [off0, off1]: |
| 6194 | ldt = dt + off |
| 6195 | if ldt.utcoffset() == off: |
| 6196 | return ldt |
| 6197 | ldt = ldt.replace(fold=1) |
| 6198 | if ldt.utcoffset() == off: |
| 6199 | return ldt |
| 6200 | |
| 6201 | raise ValueError("No suitable local time found") |
| 6202 | |
| 6203 | # Reimplementing simplified US timezones to respect the "fold" flag: |
| 6204 |
no test coverage detected