getDateTimeWeekDay function

DateTimeWeekDay? getDateTimeWeekDay(
  1. int? weekDayIndex
)

Returns enum DateTimeWeekDay by weekDayIndex (from 1 to 7). See getDateTimeWeekDayIndex.

Implementation

DateTimeWeekDay? getDateTimeWeekDay(int? weekDayIndex) {
  if (weekDayIndex == null) return null;

  switch (weekDayIndex) {
    case 1:
      return DateTimeWeekDay.monday;
    case 2:
      return DateTimeWeekDay.tuesday;
    case 3:
      return DateTimeWeekDay.wednesday;
    case 4:
      return DateTimeWeekDay.thursday;
    case 5:
      return DateTimeWeekDay.friday;
    case 6:
      return DateTimeWeekDay.saturday;
    case 7:
      return DateTimeWeekDay.sunday;
    default:
      throw ArgumentError(
          'Invalid DateTime weekDay index. Should be of range 1-7, where Monday is 1 and Sunday is 7 (Monday-to-Sunday week).');
  }
}