getDaysInMonth static method

int getDaysInMonth(
  1. int year,
  2. int month, [
  3. bool isPersian = false
])

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 1582. It will not give valid results for dates prior to that time.

Implementation

// ignore: avoid_positional_boolean_parameters
static int getDaysInMonth(int year, int month, [bool isPersian = false]) {
  if (isPersian) {
    return Jalali.fromDateTime(DateTime(year, month)).monthLength;
  } else {
    if (month == DateTime.february) {
      final isLeapYear =
          (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
      if (isLeapYear) {
        return 29;
      }
      return 28;
    }
    return _daysInMonth[month - 1];
  }
}