Skip to content

Instantly share code, notes, and snippets.

@asmallteapot
Created February 8, 2012 18:04
Show Gist options
  • Select an option

  • Save asmallteapot/1771793 to your computer and use it in GitHub Desktop.

Select an option

Save asmallteapot/1771793 to your computer and use it in GitHub Desktop.
I love^W**HATE** date programming on iOS.
- (BOOL)currentlyOpen {
int weekday = [[[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:[NSDate date]] weekday];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(weekdayFrom <= %d OR weekdayTo >= %d) AND ANY location.resourceUri like %@", weekday, weekday, self.resourceUri];
Hours *hours = [Hours findFirstWithPredicate:predicate];
int currentHour = [[[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]] hour];
if ([hours.hourFrom intValue] <= currentHour && [hours.hourTo intValue] >= currentHour) {
return YES;
} else {
return NO;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment