getNoOfSpaceRequiredBeforeFirstValidDate static method

int getNoOfSpaceRequiredBeforeFirstValidDate(
  1. List<int> weekdaysToHide,
  2. int weekdayValueForFirstValidDay, [
  3. bool isSundayFirstDayOfWeek = false
])

This method returns the number of spaces required before first valid based of the hidden weekdays. For example, if the first valid date falls on a Tuesday, that means that the weekday "monday" is hidden, which makes the first valid date index "1"

Implementation

static int getNoOfSpaceRequiredBeforeFirstValidDate(
  List<int> weekdaysToHide,
  int weekdayValueForFirstValidDay, [
  bool isSundayFirstDayOfWeek = false,
]) {
  final mondayWeekDayList = [1, 2, 3, 4, 5, 6, 7];
  final sundayWeekDayList = [7, 1, 2, 3, 4, 5, 6];

  mondayWeekDayList.removeWhere(
    (weekday) => weekdaysToHide.contains(weekday),
  );
  sundayWeekDayList.removeWhere(
    (weekday) => weekdaysToHide.contains(weekday),
  );

  return isSundayFirstDayOfWeek
      ? sundayWeekDayList.indexOf(weekdayValueForFirstValidDay)
      : mondayWeekDayList.indexOf(weekdayValueForFirstValidDay);
}