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.

Revisions

  1. brennanMKE created this gist Dec 14, 2014.
    10 changes: 10 additions & 0 deletions isNowAGoodTimeForADrink.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    - (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);
    }