runPresetsAndExceptions method

dynamic runPresetsAndExceptions (
  1. dynamic selectedDate,
  2. dynamic startDate,
  3. dynamic endDate
)

Implementation

runPresetsAndExceptions(selectedDate, startDate, endDate) {
  if ((startDate == null && endDate != null) || (startDate != null && endDate == null)) {
    throw Exception("Both 'startDate' and 'endDate' are mandatory to specify range");
  } else if (selectedDate != null && (isDateBefore(selectedDate, startDate) || isDateAfter(selectedDate, endDate))) {
    throw Exception("Selected Date is out of range from start and end dates");
  } else if (startDate == null && startDate == null) {
    doesDateRangeExists = false;
  } else {
    doesDateRangeExists = true;
  }
  if (doesDateRangeExists) {
    if (endDate != null && isDateAfter(currentDate, endDate)) {
      currentDate = getDateOnly(startDate);
    } else if (isDateBefore(currentDate, startDate)) {
      currentDate = getDateOnly(startDate);
    }
  }
  if (selectedDate != null) {
    currentDate = getDateOnly(nullOrDefault(selectedDate, currentDate));
  }
}