isDateSelectable static method

bool isDateSelectable(
  1. DateTime selectedDate,
  2. DateTime? from,
  3. DateTime? to,
  4. Map<String, Map<String, dynamic>> blockedDates,
  5. Map<String, List<TimeRange>>? availability,
)

Implementation

static bool isDateSelectable(
    DateTime selectedDate,
    DateTime? from,
    DateTime? to,
    Map<String, Map<String, dynamic>> blockedDates,
    Map<String, List<TimeRange>>? availability) {
  String day = DateFormat('yMd').format(selectedDate);
  DateTime now = DateTime.now();
  bool isBlocked = blockedDates.containsKey(day) &&
      blockedDates[day]?["fullDayOut"] == true;
  bool isNotAvailable = availability != null &&
      (availability[SchedulerUtils.weekdays[selectedDate.weekday - 1]] ==
              null ||
          (availability[SchedulerUtils.weekdays[selectedDate.weekday - 1]] !=
                  null &&
              availability[SchedulerUtils.weekdays[selectedDate.weekday - 1]]!
                  .isEmpty));

  if (isBlocked) {
    return false;
  }
  if (isNotAvailable) {
    return false;
  }
  return selectedDate.isAtSameMomentAs(from ?? now) ||
      selectedDate.isAfter(from ?? now) ||
      selectedDate.isAtSameMomentAs(selectedDate) ||
      selectedDate.isBefore(to ?? now.add(const Duration(days: 1)));
}