def _days_in_month(year, month):
"year, month -> number of days in that month in that year."
- assert 1 <= month <= 12, month
+ assert 1 <= month <= 12, f"month must be in 1..12, not {month}"
if month == 2 and _is_leap(year):
return 29
return _DAYS_IN_MONTH[month]
if became_next_day:
year, month, day = date_components
# Only wrap day/month when it was previously valid
- if month <= 12 and day <= (days_in_month := _days_in_month(year, month)):
+ if 1 <= month <= 12 and day <= (days_in_month := _days_in_month(year, month)):
# Calculate midnight of the next day
day += 1
if day > days_in_month:
"2009-04-01T12:30:90", # Second out of range
"2009-04-01T12:90:45", # Minute out of range
"2009-04-01T25:30:45", # Hour out of range
+ "2009-00-01T24:00:00", # Month below range
"2009-13-01T24:00:00", # Month out of range
"9999-12-31T24:00:00", # Year out of range
]
goto error;
}
- if ((hour == 24) && (month <= 12)) {
+ if ((hour == 24) && (month >= 1 && month <= 12)) {
int d_in_month = days_in_month(year, month);
if (day <= d_in_month) {
if (minute == 0 && second == 0 && microsecond == 0) {