isDateSelectable static method
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)));
}