mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
gh-122272: Guarantee specifiers %F and %C for datetime.strftime to be 0-padded (GH-122436)
This commit is contained in:
parent
7cd3aa42f0
commit
126910edba
7 changed files with 145 additions and 14 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue