daysInMonth static method

List<DateTime> daysInMonth(
  1. DateTime month
)

The list of days in a given month

Implementation

static List<DateTime> daysInMonth(DateTime month) {
  var first = firstDayOfMonth(month);
  var daysBefore = first.weekday;
  var firstToDisplay = first.subtract(Duration(days: daysBefore));
  var last = DateUtils.lastDayOfMonth(month);

  var daysAfter = 7 - last.weekday;

  // If the last day is sunday (7) the entire week must be rendered
  if (daysAfter == 0) {
    daysAfter = 7;
  }

  var lastToDisplay = last.add(Duration(days: daysAfter));
  return daysInRange(firstToDisplay, lastToDisplay).toList();
}