GH-90750: Use datetime.fromisocalendar in _strptime (#103802)

Use datetime.fromisocalendar in _strptime

This unifies the ISO → Gregorian conversion logic and improves handling
of invalid ISO weeks.
This commit is contained in:
Paul Ganssle 2023-04-27 10:27:27 -06:00 committed by GitHub
parent b701dce340
commit a5308e188b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View file

@ -242,6 +242,16 @@ class StrptimeTests(unittest.TestCase):
# 5. Julian/ordinal day (%j) is specified with %G, but not %Y
with self.assertRaises(ValueError):
_strptime._strptime("1999 256", "%G %j")
# 6. Invalid ISO weeks
invalid_iso_weeks = [
"2019-00-1",
"2019-54-1",
"2021-53-1",
]
for invalid_iso_dtstr in invalid_iso_weeks:
with self.subTest(invalid_iso_dtstr):
with self.assertRaises(ValueError):
_strptime._strptime(invalid_iso_dtstr, "%G-%V-%u")
def test_strptime_exception_context(self):