gh-83861: Fix datetime.astimezone() method (GH-101545)

This commit is contained in:
Alexander Belopolsky 2023-04-19 17:02:29 -04:00 committed by GitHub
parent d4aa8578b1
commit 2b1260c557
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

View file

@ -1965,6 +1965,11 @@ class datetime(date):
def _local_timezone(self):
if self.tzinfo is None:
ts = self._mktime()
# Detect gap
ts2 = self.replace(fold=1-self.fold)._mktime()
if ts2 != ts: # This happens in a gap or a fold
if (ts2 > ts) == self.fold:
ts = ts2
else:
ts = (self - _EPOCH) // timedelta(seconds=1)
localtm = _time.localtime(ts)