Skip to content

Commit

Permalink
Makes 'today' nullable
Browse files Browse the repository at this point in the history
Makes ‘today’ nullable
  • Loading branch information
WenchaoD committed Aug 30, 2016
1 parent aba7575 commit 698db15
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion FSCalendar.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "FSCalendar"
s.version = "2.3.1"
s.version = "2.3.2.beta"
s.summary = "A superiorly awesome iOS7+ calendar control, compatible with both Objective-C and Swift2."

s.homepage = "https://github.com/WenchaoD/FSCalendar"
Expand Down
2 changes: 1 addition & 1 deletion FSCalendar/FSCalendar+DateTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ - (BOOL)isDate:(NSDate *)date1 equalToDate:(NSDate *)date2 toCalendarUnit:(FSCal

- (BOOL)isDateInToday:(NSDate *)date
{
return [self isDate:date equalToDate:self.today toCalendarUnit:FSCalendarUnitDay];
return [self isDate:date equalToDate:[NSDate date] toCalendarUnit:FSCalendarUnitDay];
}

- (NSString *)stringFromDate:(NSDate *)date format:(NSString *)format
Expand Down
4 changes: 2 additions & 2 deletions FSCalendar/FSCalendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ IB_DESIGNABLE
@property (weak, nonatomic) IBOutlet id<FSCalendarDataSource> dataSource;

/**
* A special mark will be put on today of the calendar
* A special mark will be put on 'today' of the calendar.
*/
@property (strong, nonatomic) NSDate *today;
@property (nullable, strong, nonatomic) NSDate *today;

/**
* The current page of calendar
Expand Down
51 changes: 28 additions & 23 deletions FSCalendar/FSCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -787,31 +787,34 @@ - (void)setFirstWeekday:(NSUInteger)firstWeekday
- (void)setToday:(NSDate *)today
{
[self requestBoundingDatesIfNecessary];
if ([self daysFromDate:_minimumDate toDate:today] < 0) {
today = _minimumDate.copy;
} else if ([self daysFromDate:_maximumDate toDate:today] > 0) {
today = _maximumDate.copy;
}
if (![self isDateInToday:today]) {
_today = [self dateByIgnoringTimeComponentsOfDate:today];
switch (_scope) {
case FSCalendarScopeMonth: {
_currentPage = [self beginingOfMonthOfDate:today];
break;
}
case FSCalendarScopeWeek: {
_currentPage = [self beginingOfWeekOfDate:today];
break;
if (!today) {
_today = nil;
} else {
if ([self daysFromDate:_minimumDate toDate:today] < 0) {
today = _minimumDate.copy;
} else if ([self daysFromDate:_maximumDate toDate:today] > 0) {
today = _maximumDate.copy;
}
if (![self isDateInToday:today]) {
_today = [self dateByIgnoringTimeComponentsOfDate:today];
switch (_scope) {
case FSCalendarScopeMonth: {
_currentPage = [self beginingOfMonthOfDate:today];
break;
}
case FSCalendarScopeWeek: {
_currentPage = [self beginingOfWeekOfDate:today];
break;
}
}
_needsAdjustingMonthPosition = YES;
[self setNeedsLayout];
}
_needsAdjustingMonthPosition = YES;
[self setNeedsLayout];

[_collectionView.visibleCells makeObjectsPerformSelector:@selector(setDateIsToday:) withObject:@NO];
[[_collectionView cellForItemAtIndexPath:[self indexPathForDate:today]] setValue:@YES forKey:@"dateIsToday"];
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];

}

[_collectionView.visibleCells makeObjectsPerformSelector:@selector(setDateIsToday:) withObject:@NO];
[[_collectionView cellForItemAtIndexPath:[self indexPathForDate:today]] setValue:@YES forKey:@"dateIsToday"];
[_collectionView.visibleCells makeObjectsPerformSelector:@selector(setNeedsLayout)];
}

- (void)setCurrentPage:(NSDate *)currentPage
Expand Down Expand Up @@ -1342,6 +1345,7 @@ - (void)scrollToPageForDate:(NSDate *)date animated:(BOOL)animated

- (NSDate *)dateForIndexPath:(NSIndexPath *)indexPath scope:(FSCalendarScope)scope
{
if (!indexPath) return nil;
switch (scope) {
case FSCalendarScopeMonth: {
NSDate *currentPage = [self dateByAddingMonths:indexPath.section toDate:[self beginingOfMonthOfDate:_minimumDate]];
Expand Down Expand Up @@ -1379,6 +1383,7 @@ - (NSDate *)dateForIndexPath:(NSIndexPath *)indexPath

- (NSIndexPath *)indexPathForDate:(NSDate *)date scope:(FSCalendarScope)scope
{
if (!date) return nil;
NSInteger item = 0;
NSInteger section = 0;
switch (scope) {
Expand Down Expand Up @@ -1611,7 +1616,7 @@ - (void)reloadDataForCell:(FSCalendarCell *)cell atIndexPath:(NSIndexPath *)inde
cell.title = [self titleForDate:cell.date];
cell.subtitle = [self subtitleForDate:cell.date];
cell.dateIsSelected = [_selectedDates containsObject:cell.date];
cell.dateIsToday = [self isDateInToday:cell.date];
cell.dateIsToday = self.today? [self isDateInToday:cell.date] : NO;
switch (_scope) {
case FSCalendarScopeMonth: {
NSDate *firstPage = [self beginingOfMonthOfDate:_minimumDate];
Expand Down
2 changes: 1 addition & 1 deletion FSCalendar/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.3.1</string>
<string>2.3.2.beta</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit 698db15

Please sign in to comment.