You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]
while tempDate < to {
tempDate = Calendar.current.date(byAdding: .day, value: 1, to: tempDate)!
array.append(tempDate)
}
return array
}
Please help me on this as it takes upto 10 seconds to load calendar view.
Thanks.
The text was updated successfully, but these errors were encountered:
seekingdesti
changed the title
calendarView set Available Dates taking long time to load calendar
calendarView set Available Dates function taking long time to load calendar
Aug 16, 2023
seekingdesti
changed the title
calendarView set Available Dates function taking long time to load calendar
calendarView setAvailableDates function taking long time to load calendar view
Aug 16, 2023
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]
The text was updated successfully, but these errors were encountered: