How can i calculate the number of days in a year for any calendar, not just gregorian. I have tried this
NSUInteger *days = [[NSCalendar currentCalendar] range
In general you may use number of days between 1st day of the year and 1st day of the next year. Here's the code that illustrates this approach
- (NSDate *)firstDateOfYear:(NSInteger)year
{
NSDateComponents *dc = [[NSDateComponents alloc] init];
dc.year = year;
dc.month = 1;
dc.day = 1;
return [[NSCalendar currentCalendar] dateFromComponents:dc];
}
- (NSUInteger)numberOfDaysInYear:(NSInteger)year
{
NSDate *firstDateOfYear = [self firstDateOfYear:year];
NSDate *firstDateOfNextYear = [self firstDateOfYear:year + 1];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit fromDate:firstDateOfYear toDate:firstDateOfNextYear options:0];
return [components day];
}