weekendsCount static method

int weekendsCount(
  1. int year,
  2. int month
)

Get weekends count

Implementation

static int weekendsCount(int year, int month) {
  int count = 0;
  // Number of days in the month
  int daysInMonth = DateTime(year, month + 1, 0).day;

  for (int i = 1; i <= daysInMonth; i++) {
    DateTime day = DateTime(year, month, i);
    // Check if the day is a Saturday (6) or Sunday (7)
    if (day.weekday == DateTime.saturday || day.weekday == DateTime.sunday) {
      count++;
    }
  }

  return count;
}