getDateTimeWeekDayIndex function

int? getDateTimeWeekDayIndex(
  1. DateTimeWeekDay? weekDay
)

Gets index of DateTimeWeekDay, starting from 1 (Monday) to 7 (Sunday), same range as DateTime.wednesday .

Implementation

int? getDateTimeWeekDayIndex(DateTimeWeekDay? weekDay) {
  if (weekDay == null) return null;

  switch (weekDay) {
    case DateTimeWeekDay.monday:
      return 1;
    case DateTimeWeekDay.tuesday:
      return 2;
    case DateTimeWeekDay.wednesday:
      return 3;
    case DateTimeWeekDay.thursday:
      return 4;
    case DateTimeWeekDay.friday:
      return 5;
    case DateTimeWeekDay.saturday:
      return 6;
    case DateTimeWeekDay.sunday:
      return 7;
    default:
      return null;
  }
}