Skip to content

Commit

Permalink
Remove deprecation warnings in Xcode v6.3.1 by updating calendar symb…
Browse files Browse the repository at this point in the history
…ols to iOS8 versions.
  • Loading branch information
adonoho committed Apr 29, 2015
1 parent 9903b50 commit ae48242
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions PDTSimpleCalendar/PDTSimpleCalendarViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ -(void)setCalendar:(NSCalendar*)calendar
{
_calendar = calendar;
self.headerDateFormatter.calendar = calendar;
self.daysPerWeek = [_calendar maximumRangeOfUnit:NSWeekdayCalendarUnit].length;
self.daysPerWeek = [_calendar maximumRangeOfUnit:NSCalendarUnitWeekday].length;
}

- (NSDate *)firstDate
Expand Down Expand Up @@ -189,7 +189,7 @@ - (void)setSelectedDate:(NSDate *)newSelectedDate
}

//Test if selectedDate between first & last date
NSDate *startOfDay = [self clampDate:newSelectedDate toComponents:NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit];
NSDate *startOfDay = [self clampDate:newSelectedDate toComponents:NSCalendarUnitDay|NSCalendarUnitMonth|NSCalendarUnitYear];
if (([startOfDay compare:self.firstDateMonth] == NSOrderedAscending) || ([startOfDay compare:self.lastDateMonth] == NSOrderedDescending)) {
//the newSelectedDate is not between first & last date of the calendar, do nothing.
return;
Expand Down Expand Up @@ -304,13 +304,13 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
//Each Section is a Month
return [self.calendar components:NSMonthCalendarUnit fromDate:self.firstDateMonth toDate:self.lastDateMonth options:0].month + 1;
return [self.calendar components:NSCalendarUnitMonth fromDate:self.firstDateMonth toDate:self.lastDateMonth options:0].month + 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSDate *firstOfMonth = [self firstOfMonthForSection:section];
NSRange rangeOfWeeks = [self.calendar rangeOfUnit:NSWeekCalendarUnit inUnit:NSMonthCalendarUnit forDate:firstOfMonth];
NSRange rangeOfWeeks = [self.calendar rangeOfUnit:NSCalendarUnitWeekOfMonth inUnit:NSCalendarUnitMonth forDate:firstOfMonth];

//We need the number of calendar weeks for the full months (it will maybe include previous month and next months cells)
return (rangeOfWeeks.length * self.daysPerWeek);
Expand All @@ -327,8 +327,8 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
NSDate *firstOfMonth = [self firstOfMonthForSection:indexPath.section];
NSDate *cellDate = [self dateForCellAtIndexPath:indexPath];

NSDateComponents *cellDateComponents = [self.calendar components:NSDayCalendarUnit|NSMonthCalendarUnit fromDate:cellDate];
NSDateComponents *firstOfMonthsComponents = [self.calendar components:NSMonthCalendarUnit fromDate:firstOfMonth];
NSDateComponents *cellDateComponents = [self.calendar components:NSCalendarUnitDay|NSCalendarUnitMonth fromDate:cellDate];
NSDateComponents *firstOfMonthsComponents = [self.calendar components:NSCalendarUnitMonth fromDate:firstOfMonth];

BOOL isToday = NO;
BOOL isSelected = NO;
Expand Down Expand Up @@ -382,8 +382,8 @@ - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtInde
return NO;
}

NSDateComponents *cellDateComponents = [self.calendar components:NSDayCalendarUnit|NSMonthCalendarUnit fromDate:cellDate];
NSDateComponents *firstOfMonthsComponents = [self.calendar components:NSMonthCalendarUnit fromDate:firstOfMonth];
NSDateComponents *cellDateComponents = [self.calendar components:NSCalendarUnitDay|NSCalendarUnitMonth fromDate:cellDate];
NSDateComponents *firstOfMonthsComponents = [self.calendar components:NSCalendarUnitMonth fromDate:firstOfMonth];

return (cellDateComponents.month == firstOfMonthsComponents.month);
}
Expand Down Expand Up @@ -481,7 +481,7 @@ - (BOOL)isSelectedDate:(NSDate *)date

- (BOOL)isEnabledDate:(NSDate *)date
{
NSDate *clampedDate = [self clampDate:date toComponents:(NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit)];
NSDate *clampedDate = [self clampDate:date toComponents:(NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay)];
if (([clampedDate compare:self.firstDate] == NSOrderedAscending) || ([clampedDate compare:self.lastDate] == NSOrderedDescending)) {
return NO;
}
Expand All @@ -495,8 +495,8 @@ - (BOOL)isEnabledDate:(NSDate *)date

- (BOOL)clampAndCompareDate:(NSDate *)date withReferenceDate:(NSDate *)referenceDate
{
NSDate *refDate = [self clampDate:referenceDate toComponents:(NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit)];
NSDate *clampedDate = [self clampDate:date toComponents:(NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit)];
NSDate *refDate = [self clampDate:referenceDate toComponents:(NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay)];
NSDate *clampedDate = [self clampDate:date toComponents:(NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay)];

return [refDate isEqualToDate:clampedDate];
}
Expand All @@ -513,14 +513,14 @@ - (NSDate *)firstOfMonthForSection:(NSInteger)section

- (NSInteger)sectionForDate:(NSDate *)date
{
return [self.calendar components:NSMonthCalendarUnit fromDate:self.firstDateMonth toDate:date options:0].month;
return [self.calendar components:NSCalendarUnitMonth fromDate:self.firstDateMonth toDate:date options:0].month;
}


- (NSDate *)dateForCellAtIndexPath:(NSIndexPath *)indexPath
{
NSDate *firstOfMonth = [self firstOfMonthForSection:indexPath.section];
NSInteger ordinalityOfFirstDay = [self.calendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSWeekCalendarUnit forDate:firstOfMonth];
NSInteger ordinalityOfFirstDay = [self.calendar ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitWeekOfMonth forDate:firstOfMonth];
NSDateComponents *dateComponents = [NSDateComponents new];
dateComponents.day = (1 - ordinalityOfFirstDay) + indexPath.item;

Expand All @@ -537,11 +537,11 @@ - (NSIndexPath *)indexPathForCellAtDate:(NSDate *)date
NSInteger section = [self sectionForDate:date];

NSDate *firstOfMonth = [self firstOfMonthForSection:section];
NSInteger ordinalityOfFirstDay = [self.calendar ordinalityOfUnit:NSDayCalendarUnit inUnit:NSWeekCalendarUnit forDate:firstOfMonth];
NSInteger ordinalityOfFirstDay = [self.calendar ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitWeekOfMonth forDate:firstOfMonth];


NSDateComponents *dateComponents = [self.calendar components:NSDayCalendarUnit fromDate:date];
NSDateComponents *firstOfMonthComponents = [self.calendar components:NSDayCalendarUnit fromDate:firstOfMonth];
NSDateComponents *dateComponents = [self.calendar components:NSCalendarUnitDay fromDate:date];
NSDateComponents *firstOfMonthComponents = [self.calendar components:NSCalendarUnitDay fromDate:firstOfMonth];
NSInteger item = (dateComponents.day - firstOfMonthComponents.day) - (1 - ordinalityOfFirstDay);

return [NSIndexPath indexPathForItem:item inSection:section];
Expand Down

0 comments on commit ae48242

Please sign in to comment.