Created
April 17, 2012 16:09
-
-
Save nmondollot/2407213 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSInteger)length | |
{ | |
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
NSDateComponents *components = [calendar components:NSDayCalendarUnit | |
fromDate:self.dateFrom | |
toDate:self.dateTo | |
options:0]; | |
double days = (double)components.day; | |
// handle edge cases | |
if(timeOfDayFrom.time == TimeOfDayMorning && timeOfDayTo.time == TimeOfDayEvening) | |
days += 0.5f; | |
if(timeOfDayFrom.time == TimeOfDayEvening && timeOfDayTo.time == TimeOfDayMorning) | |
days -= 0.5f; | |
NSInteger total = round(days); | |
return (total >= 1) ? total : 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment