Created
December 14, 2014 01:09
-
-
Save brennanMKE/24a0c119917b97d73ada to your computer and use it in GitHub Desktop.
isNowAGoodTimeForADrink
This file contains 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)isNowAGoodTimeForADrink { | |
NSDate *now = [NSDate date]; | |
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
NSDateComponents *components = [gregorian components:NSCalendarUnitWeekday|NSCalendarUnitHour fromDate:now]; | |
BOOL isWeekend = components.weekday == 7 || components.weekday == 0; // sat or sun | |
// it is a good time for a drink on weekends after 11am and weekdays after 5pm | |
return (isWeekend && components.hour >= 11) || (!isWeekend && components.hour >= 17); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment