Skip to content

Commit d2e66d4

Browse files
committed
Keep accepting year 0 with a 24:00 time that rolls over into year 1
1 parent 6006f8f commit d2e66d4

4 files changed

Lines changed: 3 additions & 5 deletions

File tree

‎Lib/_pydatetime.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,8 +1936,7 @@ def fromisoformat(cls, date_string):
19361936
if became_next_day:
19371937
year, month, day = date_components
19381938
# Only wrap day/month when it was previously valid
1939-
if (year >= MINYEAR and 1 <= month <= 12 and
1940-
1 <= day <= (days_in_month := _days_in_month(year, month))):
1939+
if 1 <= month <= 12 and 1 <= day <= (days_in_month := _days_in_month(year, month)):
19411940
# Calculate midnight of the next day
19421941
day += 1
19431942
if day > days_in_month:

‎Lib/test/datetimetester.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4126,7 +4126,6 @@ def test_fromisoformat_fails_datetime_valueerror(self):
41264126
"2009-04-01T25:30:45", # Hour out of range
41274127
"2009-00-01T24:00:00", # Month below range
41284128
"2009-13-01T24:00:00", # Month out of range
4129-
"0000-12-31T24:00:00", # Year below range
41304129
"9999-12-31T24:00:00", # Year out of range
41314130
]
41324131

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Fix :meth:`datetime.datetime.fromisoformat` to raise :exc:`ValueError` for a
2-
day or year of ``0`` combined with a ``24:00`` time, instead of returning the
2+
day of ``0`` combined with a ``24:00`` time, instead of returning the
33
following date.

‎Modules/_datetimemodule.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6215,7 +6215,7 @@ datetime_datetime_fromisoformat_impl(PyTypeObject *type, PyObject *string)
62156215
goto error;
62166216
}
62176217

6218-
if ((hour == 24) && (year >= MINYEAR) && (month >= 1 && month <= 12)) {
6218+
if ((hour == 24) && (month >= 1 && month <= 12)) {
62196219
int d_in_month = days_in_month(year, month);
62206220
if (day >= 1 && day <= d_in_month) {
62216221
if (minute == 0 && second == 0 && microsecond == 0) {

0 commit comments

Comments
 (0)