https://github.com/python/cpython/commit/568af27445751ebae458d21dad76baa36ff19804 commit: 568af27445751ebae458d21dad76baa36ff19804 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: StanFromIreland <[email protected]> date: 2026-10-22T07:34:55+01:00 summary:
[3.15] gh-159706: Fix pure-Python ZoneInfo.fromutc() fold detection for single-transition zones (GH-159828) (#160152) (cherry picked from commit 1c5b959ca9110a9ec3e7e51d37b6c48fc7110d11) Co-authored-by: Lazizbek Ergashev <[email protected]> files: A Misc/NEWS.d/next/Library/2026-10-19-16-49-09.gh-issue-159706.ushGrx.rst M Lib/test/test_zoneinfo/test_zoneinfo.py M Lib/zoneinfo/_zoneinfo.py diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index c6393743e93c3d..40696b09d95719 100644 --- a/Lib/test/test_zoneinfo/test_zoneinfo.py +++ b/Lib/test/test_zoneinfo/test_zoneinfo.py @@ -642,6 +642,26 @@ def test_one_transition(self): dt_utc_actual = dt_local.astimezone(timezone.utc) self.assertEqual(dt_utc_actual, dt_utc) + def test_one_transition_fold(self): + GMT = ZoneOffset("-00", ZERO) + N03 = ZoneOffset("-03", -timedelta(hours=3)) + + transitions = [ + ZoneTransition(datetime(1976, 12, 1), GMT, N03), + ] + + after = "<-03>3" + + zf = self.construct_zone(transitions, after) + zi = self.klass.from_file(zf) + + dt_utc = datetime(1976, 12, 1, 1, tzinfo=timezone.utc) + dt_local = dt_utc.astimezone(zi) + + self.assertEqual(dt_local.fold, 1) + self.assertEqual(dt_local.utcoffset(), N03.utcoffset) + self.assertEqual(dt_local.astimezone(timezone.utc), dt_utc) + def test_one_zone_dst(self): DST = ZoneOffset("DST", ONE_H, ONE_H) transitions = [ diff --git a/Lib/zoneinfo/_zoneinfo.py b/Lib/zoneinfo/_zoneinfo.py index c7ec9b1bf36e22..7cdb4c22fa8932 100644 --- a/Lib/zoneinfo/_zoneinfo.py +++ b/Lib/zoneinfo/_zoneinfo.py @@ -144,7 +144,7 @@ def fromutc(self, dt): if num_trans > 1 and timestamp >= self._trans_utc[1]: tti_prev, tti = self._ttinfos[idx - 2 : idx] elif timestamp > self._trans_utc[-1]: - tti_prev = self._ttinfos[-1] + tti_prev = self._tti_before tti = self._tz_after else: tti_prev = self._tti_before diff --git a/Misc/NEWS.d/next/Library/2026-10-19-16-49-09.gh-issue-159706.ushGrx.rst b/Misc/NEWS.d/next/Library/2026-10-19-16-49-09.gh-issue-159706.ushGrx.rst new file mode 100644 index 00000000000000..ee90605ed0af2b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-19-16-49-09.gh-issue-159706.ushGrx.rst @@ -0,0 +1,3 @@ +Fix the pure-Python :class:`zoneinfo.ZoneInfo` setting ``fold=0`` in +:meth:`~datetime.tzinfo.fromutc` for times in the fold created by the only +transition of a zone with a single transition. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
