mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-102450: Add ISO-8601 alternative for midnight to fromisoformat()
calls. (#105856)
* Add NEWS.d entry * Allow ISO-8601 24:00 alternative to midnight on datetime.time.fromisoformat() * Allow ISO-8601 24:00 alternative to midnight on datetime.datetime.fromisoformat() * Add NEWS.d entry * Improve error message when hour is 24 and minute/second/microsecond is not 0 * Add tests for 24:00 fromisoformat * Remove duplicate call to days_in_month() by storing in variable * Add Python implementation * Fix Lint * Fix differing error msg in datetime.fromisoformat implementations when 24hrs has non-zero time component(s) * Fix using time components inside tzinfo in Python implementation * Don't parse tzinfo in C implementation when invalid iso midnight * Remove duplicated variable in datetime test assertion line * Add self to acknowledgements * Remove duplicate NEWS entry * Linting * Add missing test case for when wrapping the year makes it invalid (too large)
This commit is contained in:
parent
68e384c217
commit
b0c6cf5f17
5 changed files with 80 additions and 4 deletions
|
@ -3342,6 +3342,9 @@ class TestDateTime(TestDate):
|
|||
('2025-01-02T03:04:05,678+00:00:10',
|
||||
self.theclass(2025, 1, 2, 3, 4, 5, 678000,
|
||||
tzinfo=timezone(timedelta(seconds=10)))),
|
||||
('2025-01-02T24:00:00', self.theclass(2025, 1, 3, 0, 0, 0)),
|
||||
('2025-01-31T24:00:00', self.theclass(2025, 2, 1, 0, 0, 0)),
|
||||
('2025-12-31T24:00:00', self.theclass(2026, 1, 1, 0, 0, 0))
|
||||
]
|
||||
|
||||
for input_str, expected in examples:
|
||||
|
@ -3378,6 +3381,12 @@ class TestDateTime(TestDate):
|
|||
'2009-04-19T12:30:45.123456-05:00a', # Extra text
|
||||
'2009-04-19T12:30:45.123-05:00a', # Extra text
|
||||
'2009-04-19T12:30:45-05:00a', # Extra text
|
||||
'2009-04-19T24:00:00.000001', # Has non-zero microseconds on 24:00
|
||||
'2009-04-19T24:00:01.000000', # Has non-zero seconds on 24:00
|
||||
'2009-04-19T24:01:00.000000', # Has non-zero minutes on 24:00
|
||||
'2009-04-32T24:00:00.000000', # Day is invalid before wrapping due to 24:00
|
||||
'2009-13-01T24:00:00.000000', # Month is invalid before wrapping due to 24:00
|
||||
'9999-12-31T24:00:00.000000', # Year is invalid after wrapping due to 24:00
|
||||
]
|
||||
|
||||
for bad_str in bad_strs:
|
||||
|
@ -4312,7 +4321,7 @@ class TestTimeTZ(TestTime, TZInfoBase, unittest.TestCase):
|
|||
|
||||
with self.subTest(tstr=tstr):
|
||||
t_rt = self.theclass.fromisoformat(tstr)
|
||||
assert t == t_rt, t_rt
|
||||
assert t == t_rt
|
||||
|
||||
def test_fromisoformat_timespecs(self):
|
||||
time_bases = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue