monthDayCount static method
Returns the number of days in the given month and year.
Takes into account leap years for February.
Throws ArgumentError if month is not between 1 and 12.
Implementation
@useResult
static int monthDayCount({required int year, required int month}) {
if (month < DateConstants.minMonth || month > DateConstants.maxMonth) {
throw ArgumentError(_invalidMonthMessage);
}
const List<int> daysInMonth = <int>[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if (month == 2 && isLeapYear(year: year)) {
return DateConstants.daysInFebLeapYear;
}
return daysInMonth[month - 1];
}