diff options
author | blhsing <blhsing@gmail.com> | 2024-08-23 15:45:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-23 15:45:03 (GMT) |
commit | 126910edba812a01794f307b0cfa2a7f02bda190 (patch) | |
tree | e86e74c3e38f2b8cfcbe9484dc696a0c52767a3f /Lib/test | |
parent | 7cd3aa42f0cf72bf9a214e2630850879fe078377 (diff) | |
download | cpython-126910edba812a01794f307b0cfa2a7f02bda190.zip cpython-126910edba812a01794f307b0cfa2a7f02bda190.tar.gz cpython-126910edba812a01794f307b0cfa2a7f02bda190.tar.bz2 |
gh-122272: Guarantee specifiers %F and %C for datetime.strftime to be 0-padded (GH-122436)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/datetimetester.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index 38de110..0265643 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -1710,13 +1710,22 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase): (1000, 0), (1970, 0), ) - for year, offset in dataset: - for specifier in 'YG': + specifiers = 'YG' + if _time.strftime('%F', (1900, 1, 1, 0, 0, 0, 0, 1, 0)) == '1900-01-01': + specifiers += 'FC' + for year, g_offset in dataset: + for specifier in specifiers: 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}") + year += g_offset + if specifier == 'C': + expected = f"{year // 100:02d}" + else: + expected = f"{year:04d}" + if specifier == 'F': + expected += f"-01-01" + self.assertEqual(d.strftime(f"%{specifier}"), expected) def test_replace(self): cls = self.theclass |