Skip to content

Instantly share code, notes, and snippets.

@nmondollot
Created April 17, 2012 16:09
Show Gist options
  • Save nmondollot/2407213 to your computer and use it in GitHub Desktop.
Save nmondollot/2407213 to your computer and use it in GitHub Desktop.
-(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