From 31a11cd4604b9da91baafa8c9d03eec8f45c7514 Mon Sep 17 00:00:00 2001 From: Kir Chou Date: Wed, 3 Dec 2025 00:22:00 +0900 Subject: [PATCH 1/2] Force TestLocalTimeDisambiguation to run on LC_ALL=C --- Lib/test/datetimetester.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 7df27206206268..b2a010455202ec 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6,6 +6,7 @@ import fractions import io import itertools +import locale import os import pickle import random @@ -6295,6 +6296,15 @@ def fromutc(self, dt): class TestLocalTimeDisambiguation(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.old_locale = locale.setlocale(locale.LC_ALL) + locale.setlocale(locale.LC_ALL, 'C') + + @classmethod + def tearDownClass(cls): + locale.setlocale(locale.LC_ALL, cls.old_locale) + def test_vilnius_1941_fromutc(self): Vilnius = Europe_Vilnius_1941() From b596d083fc9110943c37ac22602873f3f8242ea4 Mon Sep 17 00:00:00 2001 From: Kir Chou Date: Wed, 3 Dec 2025 09:57:08 +0900 Subject: [PATCH 2/2] Change to update %c to the exact time format. --- Lib/test/datetimetester.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index b2a010455202ec..ace56aab7aceba 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -6,7 +6,6 @@ import fractions import io import itertools -import locale import os import pickle import random @@ -6296,35 +6295,26 @@ def fromutc(self, dt): class TestLocalTimeDisambiguation(unittest.TestCase): - @classmethod - def setUpClass(cls): - cls.old_locale = locale.setlocale(locale.LC_ALL) - locale.setlocale(locale.LC_ALL, 'C') - - @classmethod - def tearDownClass(cls): - locale.setlocale(locale.LC_ALL, cls.old_locale) - def test_vilnius_1941_fromutc(self): Vilnius = Europe_Vilnius_1941() gdt = datetime(1941, 6, 23, 20, 59, 59, tzinfo=timezone.utc) ldt = gdt.astimezone(Vilnius) - self.assertEqual(ldt.strftime("%c %Z%z"), + self.assertEqual(ldt.strftime("%a %b %d %H:%M:%S %Y %Z%z"), 'Mon Jun 23 23:59:59 1941 MSK+0300') self.assertEqual(ldt.fold, 0) self.assertFalse(ldt.dst()) gdt = datetime(1941, 6, 23, 21, tzinfo=timezone.utc) ldt = gdt.astimezone(Vilnius) - self.assertEqual(ldt.strftime("%c %Z%z"), + self.assertEqual(ldt.strftime("%a %b %d %H:%M:%S %Y %Z%z"), 'Mon Jun 23 23:00:00 1941 CEST+0200') self.assertEqual(ldt.fold, 1) self.assertTrue(ldt.dst()) gdt = datetime(1941, 6, 23, 22, tzinfo=timezone.utc) ldt = gdt.astimezone(Vilnius) - self.assertEqual(ldt.strftime("%c %Z%z"), + self.assertEqual(ldt.strftime("%a %b %d %H:%M:%S %Y %Z%z"), 'Tue Jun 24 00:00:00 1941 CEST+0200') self.assertEqual(ldt.fold, 0) self.assertTrue(ldt.dst()) @@ -6334,22 +6324,22 @@ def test_vilnius_1941_toutc(self): ldt = datetime(1941, 6, 23, 22, 59, 59, tzinfo=Vilnius) gdt = ldt.astimezone(timezone.utc) - self.assertEqual(gdt.strftime("%c %Z"), + self.assertEqual(gdt.strftime("%a %b %d %H:%M:%S %Y %Z"), 'Mon Jun 23 19:59:59 1941 UTC') ldt = datetime(1941, 6, 23, 23, 59, 59, tzinfo=Vilnius) gdt = ldt.astimezone(timezone.utc) - self.assertEqual(gdt.strftime("%c %Z"), + self.assertEqual(gdt.strftime("%a %b %d %H:%M:%S %Y %Z"), 'Mon Jun 23 20:59:59 1941 UTC') ldt = datetime(1941, 6, 23, 23, 59, 59, tzinfo=Vilnius, fold=1) gdt = ldt.astimezone(timezone.utc) - self.assertEqual(gdt.strftime("%c %Z"), + self.assertEqual(gdt.strftime("%a %b %d %H:%M:%S %Y %Z"), 'Mon Jun 23 21:59:59 1941 UTC') ldt = datetime(1941, 6, 24, 0, tzinfo=Vilnius) gdt = ldt.astimezone(timezone.utc) - self.assertEqual(gdt.strftime("%c %Z"), + self.assertEqual(gdt.strftime("%a %b %d %H:%M:%S %Y %Z"), 'Mon Jun 23 22:00:00 1941 UTC') def test_constructors(self):