Created
February 8, 2012 18:04
-
-
Save asmallteapot/1771793 to your computer and use it in GitHub Desktop.
I love^W**HATE** date programming on iOS.
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
| - (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