| 2068 | __replace__ = replace |
| 2069 | |
| 2070 | def _local_timezone(self): |
| 2071 | if self.tzinfo is None: |
| 2072 | ts = self._mktime() |
| 2073 | # Detect gap |
| 2074 | ts2 = self.replace(fold=1-self.fold)._mktime() |
| 2075 | if ts2 != ts: # This happens in a gap or a fold |
| 2076 | if (ts2 > ts) == self.fold: |
| 2077 | ts = ts2 |
| 2078 | else: |
| 2079 | ts = (self - _EPOCH) // timedelta(seconds=1) |
| 2080 | localtm = _time.localtime(ts) |
| 2081 | local = datetime(*localtm[:6]) |
| 2082 | # Extract TZ data |
| 2083 | gmtoff = localtm.tm_gmtoff |
| 2084 | zone = localtm.tm_zone |
| 2085 | return timezone(timedelta(seconds=gmtoff), zone) |
| 2086 | |
| 2087 | def astimezone(self, tz=None): |
| 2088 | if tz is None: |