datetime in UTC -> datetime in local time.
(self, dt)
| 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 |
no test coverage detected