WenchaoD / FSCalendar

A fully customizable iOS calendar library, compatible with Objective-C and Swift
MIT License
10.6k stars 1.94k forks source link

FSCalendar date out of bounds exception #1259

Open narendra-ct opened 3 years ago

narendra-ct commented 3 years ago

I found the crash when i set a max date to calendar. Please let me know how can i resolve this.

Terminating app due to uncaught exception 'FSCalendar date out of bounds exception', reason: 'Target date 2020/11/05 beyond bounds [2020/11/10 - 2020/11/18]' First throw call stack: ( 0 CoreFoundation 0x00007fff23c7127e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff513fbb20 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23c710bc +[NSException raise:format:] + 188 3 FSCalendar 0x0000000111fd873e FSCalendarAssertDateInBounds + 441 4 FSCalendar 0x0000000111fda1e5 -[FSCalendar selectDate:scrollToDate:atMonthPosition:] + 193 5 Sample App 0x000000010f63ccef 9 UIKitCore 0x00007fff47a13e5a -[UIViewController loadViewIfRequired] + 1084 10 UIKitCore 0x00007fff47a14277 -[UIViewController view] + 27 11 UIKitCore 0x00007fff47a2b52e -[UIViewController _setPresentationController:] + 100 12 UIKitCore 0x00007fff47a23d25 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1318 13 UIKitCore 0x00007fff47a25798 -[UIViewController _presentViewController:withAnimationController:completion:] + 4349 14 UIKitCore 0x00007fff47a2801b __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98 15 UIKitCore 0x00007fff47a28533 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511 16 UIKitCore 0x00007fff47a27f79 -[UIViewController _presentViewController:animated:completion:] + 187 17 UIKitCore 0x00007fff47a281e0 -[UIViewController presentViewController:animated:completion:] + 150 18 Sample App 0x000000010f8d75cb $s14Sample_App20WireframeC12showCalendar_7minDate03maxI05todayyAA0cD14ViewControllerC_10Foundation0I0VSgA2MtFZ + 875 19 Sample App 0x000000010f285e06 $s14Sample App 25ViewControllerC28observeForDaySelectionAction33_066E07B28550CB8698BD93F740E08AA3LLyyFy10Foundation4DateVSgA2ItcfU0 + 358 libc++abi.dylib: terminating with uncaught exception of type NSException

thrustToga commented 3 years ago

It's crashes because selected date out of range between minimum date and maximum date of

You can use this in DidSelect delegate method: if Date() < calendar.minimumDate { return Date() }

if Date() > calendar.maximumDate { return Date() }