datetime in UTC -> datetime in local time.
(self, dt)
| 5984 | class tzinfo2(tzinfo): |
| 5985 | |
| 5986 | def fromutc(self, dt): |
| 5987 | "datetime in UTC -> datetime in local time." |
| 5988 | |
| 5989 | if not isinstance(dt, datetime): |
| 5990 | raise TypeError("fromutc() requires a datetime argument") |
| 5991 | if dt.tzinfo is not self: |
| 5992 | raise ValueError("dt.tzinfo is not self") |
| 5993 | # Returned value satisfies |
| 5994 | # dt + ldt.utcoffset() = ldt |
| 5995 | off0 = dt.replace(fold=0).utcoffset() |
| 5996 | off1 = dt.replace(fold=1).utcoffset() |
| 5997 | if off0 is None or off1 is None or dt.dst() is None: |
| 5998 | raise ValueError |
| 5999 | if off0 == off1: |
| 6000 | ldt = dt + off0 |
| 6001 | off1 = ldt.utcoffset() |
| 6002 | if off0 == off1: |
| 6003 | return ldt |
| 6004 | # Now, we discovered both possible offsets, so |
| 6005 | # we can just try four possible solutions: |
| 6006 | for off in [off0, off1]: |
| 6007 | ldt = dt + off |
| 6008 | if ldt.utcoffset() == off: |
| 6009 | return ldt |
| 6010 | ldt = ldt.replace(fold=1) |
| 6011 | if ldt.utcoffset() == off: |
| 6012 | return ldt |
| 6013 | |
| 6014 | raise ValueError("No suitable local time found") |
| 6015 | |
| 6016 | # Reimplementing simplified US timezones to respect the "fold" flag: |
| 6017 |
no test coverage detected