monthDayCount static method

int monthDayCount({
  1. required int year,
  2. required int month,
})

Returns the number of days in the given month and year.

Takes into account leap years for February.

Implementation

static int monthDayCount({required int year, required int month}) {
  if (month < 1 || month > 12) {
    throw ArgumentError('Month must be between 1 and 12');
  }

  const List<int> daysInMonth = <int>[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

  if (month == 2 && isLeapYear(year: year)) {
    return 29;
  }

  return daysInMonth[month - 1];
}