Skip to content

Instantly share code, notes, and snippets.

@hsjunnesson
Created January 29, 2013 14:46
Show Gist options
  • Save hsjunnesson/4664761 to your computer and use it in GitHub Desktop.
Save hsjunnesson/4664761 to your computer and use it in GitHub Desktop.
// Block which determine whether two NSDates are on the same day
BOOL(^areDatesSameDay)(NSDate *, NSDate *) = ^(NSDate *date1, NSDate *date2) {
if (!date1 || !date2)
return NO;
NSDateComponents *day1 = [[NSCalendar currentCalendar] components:NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:date1];
NSDateComponents *day2 = [[NSCalendar currentCalendar] components:NSEraCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:date2];
if ([day1 day] == [day2 day] &&
[day1 month] == [day2 month] &&
[day1 year] == [day2 year] &&
[day1 era] == [day2 era]) {
return YES;
}
return NO;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment