getDaysInMonth method

int getDaysInMonth (int year, int month)

Returns the number of days in a month, according to the proleptic Gregorian calendar.

This applies the leap year logic introduced by the Gregorian reforms of

  1. It will not give valid results for dates prior to that time.

Implementation

static int getDaysInMonth(int year, int month) {
  if (month == DateTime.february) {
    final bool isLeapYear = (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
    if (isLeapYear)
      return 29;
    return 28;
  }
  return _daysInMonth[month - 1];
}