Open seekingdesti opened 1 year ago
find setDaysAvailability method and update it like below
func setDaysAvailability(_ availability: DaysAvailability) { daysAvailability = availability
switch availability {
case .all:
let days = months.flatMap { $0.allDays() }
days.forEach { $0.setState(.available) }
case .some(let dates):
let allDays = months.flatMap { $0.allDays() }
//allDays.forEach { $0.setState(.unavailable) }
//let availableDays = dates.flatMap { date in allDays.filter { $0.dateInDay(date) }}
//availableDays.forEach { $0.setState(.available) }
//let availableDatesSet = Set(dates)
let availableDatesSet = Set(dates.map { normalizeToMidnight(date: $0) })
availableDatesSet.forEach { print($0) }
allDays.forEach { day in
let dayStartDate = normalizeToMidnight(date: day.date)
if availableDatesSet.contains(dayStartDate) {
day.setState(.available)
} else {
day.setState(.unavailable)
}
}
}
} func normalizeToMidnight(date: Date) -> Date { var calendar = Calendar.current calendar.timeZone = TimeZone(secondsFromGMT: 0)! // Ensure the time zone is UTC return calendar.startOfDay(for: date) }
Hi,
I have 5 years dates in calendar, it's taking very long time to load calendar view. I i am using below function to load 5 years dates.
let avlblDates = datesRange(from: 01.01.2019, to: Date()) calendarView.setAvailableDates(DaysAvailability.some(avlblDates))
private func datesRange(from: Date, to: Date) -> [Date] { if from > to { return [Date]() } var tempDate = from var array = [tempDate]