VACalendar
VACalendar copied to clipboard
Disable all past dates
Hi,
Thanks for such a great custom calendar. Can you please help me how to disable all the past dates disabled from the current date.
any solution?
No answer? That means not possible with this?
Probably the only way is set DaysAvailability for ur VACalendarView, and ensure that they start from ur current date.
public enum DaysAvailability {
case all
case some([Date])
}
public class VACalendarView {
...
private var daysAvailability: DaysAvailability = .all
...
func setDaysAvailability(_ availability: DaysAvailability) {
but im not sure.
For example, this piece of code:
let formatter = DateFormatter()
formatter.dateFormat = "dd.MM.yyy"
let startDate = Date()
let endDate = formatter.date(from: "01.01.2021")!
var calendar = VACalendar(
startDate: startDate,
endDate: endDate,
calendar: defaultCalendar
)
calendarView = VACalendarView(frame: .zero, calendar: calendar)
let endavailables = formatter.date(from: "23.11.2019")!
let components = Calendar.current.dateComponents([.day], from: startDate, to: endavailables)
let numberOfDays = components.day ?? 0
let dates = (0...numberOfDays).compactMap {
return Calendar.current.date(byAdding: .day, value: $0, to: startDate)
}
let availability = DaysAvailability.some(dates)
calendarView.setAvailableDates(availability)
is gonna work like that:
Application getting crash at "let components = Calendar.current.dateComponents([.day], from: startDate, to: endavailables)"
in the latest swift version. Any help, please.
@chintanMaisuriya provide some crash information at least, no one has extrasensory skill there, I guess. And / OR provide project sample with your problem reproducible
@Maxatma I've attached a screenshot and log information here. It may help.
Fatal error: Can't form Range with upperBound < lowerBound: file /Library/Caches/com.apple.xbs/Binaries/SwiftPrebuiltSDKModules_iOS/install/TempContent/Objects/EmbeddedProjects/CrossTrain_iOS_SDK/iOS_SDK/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/swift/Swift.swiftmodule/x86_64.swiftinterface, line 4781 2020-06-02 19:57:16.973380+0530 VACalendarExample[1355:22414] Fatal error: Can't form Range with upperBound < lowerBound: file /Library/Caches/com.apple.xbs/Binaries/SwiftPrebuiltSDKModules_iOS/install/TempContent/Objects/EmbeddedProjects/CrossTrain_iOS_SDK/iOS_SDK/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/swift/Swift.swiftmodule/x86_64.swiftinterface, line 4781
@chintanMaisuriya First of all: It doesn't crash where you said before, look where it highlighted. It crashes because you create bad Range numberOfDays is lower than 0 ( numberOfDays is -192). Next time: Simply read what it says. Most of the time this is enough.
@Maxatma , while setting the available dates, it is always one day less . Ie for me the available date is 13 th Aug , 2020 , the calendar shows available date as 12 Aug 2020,
the same above code is used https://github.com/Vodolazkyi/VACalendar/issues/25#issuecomment-545478577
@nassifbasheer I don't think this has something to deal with the topic. Check ur timezones, idk Provided code was just an example. Debug and customize everything to achieve ur needs.