VACalendar icon indicating copy to clipboard operation
VACalendar copied to clipboard

Disable all past dates

Open shubhendu1988 opened this issue 6 years ago • 10 comments

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.

shubhendu1988 avatar Nov 23 '18 19:11 shubhendu1988

any solution?

javmorales avatar Jun 21 '19 17:06 javmorales

No answer? That means not possible with this?

AR77 avatar Sep 16 '19 15:09 AR77

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.

Maxatma avatar Oct 23 '19 13:10 Maxatma

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: Simulator Screen Shot - iPhone Xʀ - 2019-10-23 at 17 37 51

Maxatma avatar Oct 23 '19 14:10 Maxatma

Application getting crash at "let components = Calendar.current.dateComponents([.day], from: startDate, to: endavailables)"

in the latest swift version. Any help, please.

chintanMaisuriya avatar May 31 '20 06:05 chintanMaisuriya

@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 avatar Jun 01 '20 07:06 Maxatma

@Maxatma I've attached a screenshot and log information here. It may help.

Screen Shot 2020-06-02 at 7 57 49 PM

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 avatar Jun 02 '20 14:06 chintanMaisuriya

@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 avatar Jun 02 '20 14:06 Maxatma

@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 avatar Aug 10 '20 06:08 nassifbasheer

@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.

Maxatma avatar Aug 15 '20 06:08 Maxatma