Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Created December 14, 2014 01:09
Show Gist options
  • Save brennanMKE/24a0c119917b97d73ada to your computer and use it in GitHub Desktop.
Save brennanMKE/24a0c119917b97d73ada to your computer and use it in GitHub Desktop.
isNowAGoodTimeForADrink
- (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