summaryrefslogtreecommitdiffstats
path: root/Lib/test/datetimetester.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-07-29 18:55:28 (GMT)
committerGitHub <noreply@github.com>2024-07-29 18:55:28 (GMT)
commit9f6f8790ef39fd035f6ada1a9dfcb47d58d08fea (patch)
treead5f065b9deabd56f220456192dab1d863e6a0e2 /Lib/test/datetimetester.py
parent10cf7d6d00ad90867634114a894eb7e9f35df867 (diff)
downloadcpython-9f6f8790ef39fd035f6ada1a9dfcb47d58d08fea.zip
cpython-9f6f8790ef39fd035f6ada1a9dfcb47d58d08fea.tar.gz
cpython-9f6f8790ef39fd035f6ada1a9dfcb47d58d08fea.tar.bz2
Revert "[3.13] gh-120713: Normalize year with century for datetime.strftime (GH-120820) (GH-121144)" (GH-122408)
This reverts commit 009618f1125838af3c4afc772f2593637766fd45.
Diffstat (limited to 'Lib/test/datetimetester.py')
-rw-r--r--Lib/test/datetimetester.py32
1 files changed, 12 insertions, 20 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index ca804fe..d0ee974 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -1697,26 +1697,18 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
self.assertTrue(self.theclass.max)
def test_strftime_y2k(self):
- # Test that years less than 1000 are 0-padded; note that the beginning
- # of an ISO 8601 year may fall in an ISO week of the year before, and
- # therefore needs an offset of -1 when formatting with '%G'.
- dataset = (
- (1, 0),
- (49, -1),
- (70, 0),
- (99, 0),
- (100, -1),
- (999, 0),
- (1000, 0),
- (1970, 0),
- )
- for year, offset in dataset:
- for specifier in 'YG':
- with self.subTest(year=year, specifier=specifier):
- d = self.theclass(year, 1, 1)
- if specifier == 'G':
- year += offset
- self.assertEqual(d.strftime(f"%{specifier}"), f"{year:04d}")
+ for y in (1, 49, 70, 99, 100, 999, 1000, 1970):
+ d = self.theclass(y, 1, 1)
+ # Issue 13305: For years < 1000, the value is not always
+ # padded to 4 digits across platforms. The C standard
+ # assumes year >= 1900, so it does not specify the number
+ # of digits.
+ if d.strftime("%Y") != '%04d' % y:
+ # Year 42 returns '42', not padded
+ self.assertEqual(d.strftime("%Y"), '%d' % y)
+ # '0042' is obtained anyway
+ if support.has_strftime_extensions:
+ self.assertEqual(d.strftime("%4Y"), '%04d' % y)
def test_replace(self):
cls = self.theclass