Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calendarView setAvailableDates function taking long time to load calendar view #71

Open
seekingdesti opened this issue Aug 16, 2023 · 1 comment

Comments

@seekingdesti
Copy link

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]

    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.
@seekingdesti 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 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
@uzman
Copy link

uzman commented Aug 3, 2024

  • go to VACalendar.swift file

  • 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)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants