I'm getting this exception:
Fatal Exception: FSCalendar date out of bounds exception
Target date 2016/10/09 beyond bounds [2016/10/16 - 2016/10/09]
[FSCalendar scrollToDate] in the case for FSCalendarScopeWeek (line 1261 in my code). It's worth noting that I am using dates that are in the local timezone, so maybe the check is not taking that into consideration.
@glub Can you help with a stack trace?
Fatal Exception: FSCalendar date out of bounds exception
0 CoreFoundation 0x185fd01c0 exceptionPreprocess
1 libobjc.A.dylib 0x184a0855c objc_exception_throw
2 CoreFoundation 0x185fd0108 -[NSException initWithCoder:]
3 FSCalendar 0x100406578 FSCalendarAssertDateInBounds (FSCalendar.m:28)
4 FSCalendar 0x100408568 -FSCalendar scrollToDate:animated:
5 FSCalendar 0x100408d80 -FSCalendar scrollToPageForDate:animated:
6 FSCalendar 0x100403f90 -FSCalendar layoutSubviews
7 UIKit 0x18be1654c -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
8 QuartzCore 0x1892de40c -[CALayer layoutSublayers]
9 QuartzCore 0x1892d30e8 CA::Layer::layout_if_needed(CA::Transaction_)
10 UIKit 0x18be2afbc -[UIView(Hierarchy) layoutBelowIfNeeded]
11 FSCalendar 0x1004119b4 -FSCalendarAnimator performTransitionCompletion:animated:
12 FSCalendar 0x100410d38 -FSCalendarAnimator performScopeTransitionFromScope:toScope:animated:
13 FSCalendar 0x100403ec4 -FSCalendar layoutSubviews
14 UIKit 0x18be1654c -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
15 QuartzCore 0x1892de40c -[CALayer layoutSublayers]
16 QuartzCore 0x1892d30e8 CA::Layer::layout_if_needed(CA::Transaction_)
17 UIKit 0x18be2afbc -[UIView(Hierarchy) layoutBelowIfNeeded]
18 UIKit 0x18bed3430 -[UINavigationController _layoutViewController:]
19 UIKit 0x18bed0d14 -[UINavigationController _layoutTopViewController]
20 UIKit 0x18bee9c6c -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
21 UIKit 0x18bee9938 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:]
22 UIKit 0x18bee9590 -[UINavigationTransitionView _cleanupTransition]
23 UIKit 0x18be51b48 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
24 UIKit 0x18be4fd24 +[UIViewAnimationState popAnimationState]
25 UIKit 0x18bedce1c -[UINavigationTransitionView transition:fromView:toView:]
26 UIKit 0x18bed2b6c -[UINavigationController _startTransition:fromViewController:toViewController:]
27 UIKit 0x18bed1c38 -[UINavigationController _startDeferredTransitionIfNeeded:]
28 UIKit 0x18bed17ec -[UINavigationController __viewWillLayoutSubviews]
29 UIKit 0x18bed1750 -[UILayoutContainerView layoutSubviews]
30 UIKit 0x18be1654c -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
31 QuartzCore 0x1892de40c -[CALayer layoutSublayers]
32 QuartzCore 0x1892d30e8 CA::Layer::layout_if_needed(CA::Transaction_)
33 QuartzCore 0x1892d2fa8 CA::Layer::layout_and_display_if_needed(CA::Transaction_)
34 QuartzCore 0x18924fc64 CA::Context::commit_transaction(CA::Transaction_)
35 QuartzCore 0x1892770d0 CA::Transaction::commit()
36 QuartzCore 0x189277af0 CA::Transaction::observer_callback(__CFRunLoopObserver_, unsigned long, void*)
37 CoreFoundation 0x185f7d7dc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
38 CoreFoundation 0x185f7b40c __CFRunLoopDoObservers
39 CoreFoundation 0x185f7b89c __CFRunLoopRun
40 CoreFoundation 0x185eaa048 CFRunLoopRunSpecific
41 GraphicsServices 0x18792d198 GSEventRunModal
42 UIKit 0x18be84628 -[UIApplication _run]
43 UIKit 0x18be7f360 UIApplicationMain
44 SITU 0x100054c10 main (FoodCategory+CoreDataProperties.swift:14)
45 libdispatch.dylib 0x184e8c5b8 (Missing)
I'd rather have an assert than an exception since asserts are disabled in release code and I can't catch this exception (easily).
@glub Is this the latest in master?
I'm using the latest cocoapod version (2.4.0).
I have the same expiation with a FSCalendarScopeMonth with a minimumDate in more than one month. Seems to be related to timezone.
First investigation :
When view is initialized
In layoutSubviews _needsAdjustingMonthPosition is YES
So [self scrollToPageForDate:_pagingEnabled?_currentPage:(_currentPage?:self.selectedDate) animated:NO]; is called
_pagingEnabledis YES and _current_page is 2016-09-30 22:00:00 +0000
Then in FSCalendarAssertDateInBounds:
date is 2016-09-30 22:00:00 +0000
minimum_dateis 2016-10-31 23:00:00 +0000
minOffset = -31 => invalid
I try to fix that and propose a pull request
@mhausherr It would be nice to swap in an "assert" in place of the exception so production/release code doesn't crash. :)
This commit a6a39cc fix the consequence of the problem but not the root cause:
The error is not impacted by the timezone but only by the presence of minimumDateForCalendarin the data source.
If minimumDateForCalendar is after today you get an out of bound. The solution is to set currentPage default to minimumDate if minimumDate is after today
Fixed.
I founded the way to solve its
You just open FSCalendar.m and fix code like this
- (void)scrollToDate:(NSDate *)date animated:(BOOL)animated
{
if (!_minimumDate || !_maximumDate) {
return;
}
// Add this line
if(![FSCalendarUtils betweenDate:date minDate:_minimumDate maxDate:_maximumDate]) {
return ;
}
...
*Note that FSCalendarUtils was a file I added later
##------##
FSCalendarUtils.h
#import <Foundation/Foundation.h>
@interface FSCalendarUtils : NSObject
+(BOOL)betweenDate:(NSDate *)date minDate:(NSDate *)minDate maxDate:(NSDate *)maxDate;
@end
##------##
FSCalendarUtils.m
+(BOOL)betweenDate:(NSDate *)date minDate:(NSDate *)minDate maxDate:(NSDate *)maxDate {
BOOL condition1 = ([date compare:minDate] == NSOrderedSame) || ([date compare:minDate] == NSOrderedDescending);
BOOL condition2 = ([date compare:maxDate] == NSOrderedSame) || ([date compare:maxDate] == NSOrderedAscending);
BOOL isBetween = condition1 && condition2;
return isBetween;
}
'FSCalendar date out of bounds exception', reason: 'Target date 2019/08/08 beyond bounds [2019/08/10 - 2019/08/15]
Team, please check it No one has given a proper answer
@shantaramk did you resolve it, seems like a dead end?
I'm still experiencing this
What is the Latest pod version
This error only happy when you are set the min date, just remove it or make the selected date more than min date
Most helpful comment
'FSCalendar date out of bounds exception', reason: 'Target date 2019/08/08 beyond bounds [2019/08/10 - 2019/08/15]
Team, please check it No one has given a proper answer