Skip to content

Commit 80db364

Browse files
authored
time: check if a day is a valid day of its month (#19232)
1 parent 6af17a8 commit 80db364

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

vlib/time/date_time_parser.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ fn (mut p DateTimeParser) parse() !Time {
276276
}
277277
}
278278

279+
if month_ == 2 {
280+
feb_days_in_year := if is_leap_year(year_) { 29 } else { 28 }
281+
if day_in_month > feb_days_in_year {
282+
return error_invalid_time(0, 'February has only 28 days in the given year')
283+
}
284+
} else if day_in_month == 31 && month_ !in [1, 3, 5, 7, 8, 10, 12] {
285+
month_name := Time{
286+
month: month_
287+
}.custom_format('MMMM')
288+
return error_invalid_time(0, '${month_name} has only 30 days')
289+
}
290+
279291
return new_time(
280292
year: year_
281293
month: month_

0 commit comments

Comments
 (0)