getDateTimeWeekDay_from_ISO_8601_index function

DateTimeWeekDay? getDateTimeWeekDay_from_ISO_8601_index(
  1. int? weekDayIndex
)

Returns enum DateTimeWeekDay using weekDayIndex compliant with ISO 8601.

weekDayIndex From 0 (Monday) to 6 (Sunday).

Implementation

// ignore: non_constant_identifier_names
DateTimeWeekDay? getDateTimeWeekDay_from_ISO_8601_index(int? weekDayIndex) {
  if (weekDayIndex == null) return null;

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