getDateTimeWeekDayByName function

DateTimeWeekDay? getDateTimeWeekDayByName(
  1. String? weekDayName
)

Returns enum DateTimeWeekDay by week day name in english

Implementation

DateTimeWeekDay? getDateTimeWeekDayByName(String? weekDayName) {
  if (weekDayName == null) return null;
  weekDayName = weekDayName.toLowerCase().trim();
  if (weekDayName.isEmpty) return null;

  switch (weekDayName) {
    case 'monday':
      return DateTimeWeekDay.monday;
    case 'tuesday':
      return DateTimeWeekDay.tuesday;
    case 'wednesday':
      return DateTimeWeekDay.wednesday;
    case 'thursday':
      return DateTimeWeekDay.thursday;
    case 'friday':
      return DateTimeWeekDay.friday;
    case 'saturday':
      return DateTimeWeekDay.saturday;
    case 'sunday':
      return DateTimeWeekDay.sunday;
    default:
      throw ArgumentError('Invalid DateTime week day name. Should in English.');
  }
}