daysInMonth property

List<DateTime> get daysInMonth

Returns a list of DateTimes representing the days in the same month as this DateTime.

Implementation

List<DateTime> get daysInMonth {
  final first = firstDayOfMonth;
  // Calculate days before to align with Monday (ISO 8601 default).
  // Mon(1) -> 0, Sun(7) -> 6.
  final daysBefore = (first.weekday - 1) % DateTime.daysPerWeek;
  final firstToDisplay = first.subtract(Duration(days: daysBefore));
  final last = lastDayOfMonth;
  // Add days to include the last day and fill the week through Sunday.
  final daysAfter = DateTime.daysPerWeek - last.weekday + 1;
  final lastToDisplay = last.add(Duration(days: daysAfter));
  return firstToDisplay.daysUpTo(lastToDisplay).toList();
}