RecurrenceRule.fromJson constructor

RecurrenceRule.fromJson(
  1. Map<String, dynamic>? json
)

Implementation

RecurrenceRule.fromJson(Map<String, dynamic>? json) {
  if (json == null) {
    throw ArgumentError(ErrorMessages.fromJsonMapIsNull);
  }

  int? recurrenceFrequencyIndex = json[_recurrenceFrequencyKey];
  if (recurrenceFrequencyIndex == null || recurrenceFrequencyIndex >= RecurrenceFrequency.values.length) {
    throw ArgumentError(ErrorMessages.invalidRecurrencyFrequency);
  }
  recurrenceFrequency = RecurrenceFrequency.values[recurrenceFrequencyIndex];

  totalOccurrences = json[_totalOccurrencesKey];

  interval = json[_intervalKey];

  int? endDateMillisecondsSinceEpoch = json[_endDateKey];
  if (endDateMillisecondsSinceEpoch != null) {
    endDate =
        DateTime.fromMillisecondsSinceEpoch(endDateMillisecondsSinceEpoch);
  }

  List<dynamic>? daysOfWeekValues = json[_daysOfWeekKey];
  if (daysOfWeekValues != null && daysOfWeekValues is! List<int>) {
    daysOfWeek = daysOfWeekValues
        .cast<int>()
        .map((value) => value.getDayOfWeekEnumValue)
        .toList();
  }

  dayOfMonth = json[_dayOfMonthKey];
  monthOfYear =
      convertDynamicToInt(json[_monthOfYearKey])?.getMonthOfYearEnumValue;
  weekOfMonth =
      convertDynamicToInt(json[_weekOfMonthKey])?.getWeekNumberEnumValue;
}