Skip to content

Instantly share code, notes, and snippets.

@lilyball
Forked from Me1000/gist:3346813
Created August 14, 2012 06:20
Show Gist options
  • Select an option

  • Save lilyball/3346865 to your computer and use it in GitHub Desktop.

Select an option

Save lilyball/3346865 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
#define SECOND_INTERVAL 1
#define MINUTE_INTERVAL (SECOND_INTERVAL * 60)
#define HOUR_INTERVAL (MINUTE_INTERVAL * 60)
#define DAY_INTERVAL (HOUR_INTERVAL * 24)
#define WEEK_INTERVAL (DAY_INTERVAL * 7)
int main(int argc, char *argv[]) {
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
NSDate *now = [NSDate date];
NSInteger time = (NSInteger)[now timeIntervalSinceReferenceDate];
NSInteger mod = time % DAY_INTERVAL;
NSInteger expectedValue = (NSInteger)[now timeIntervalSinceReferenceDate];
while (expectedValue - DAY_INTERVAL >= 0)
expectedValue -= DAY_INTERVAL;
NSLog(@"Day: %d", DAY_INTERVAL);
NSLog(@"Time: %d", time);
NSLog(@"Modded value: %d", mod);
NSLog(@"Loopy value: %d", expectedValue);
NSLog(@"Is this right? %@", expectedValue == mod ? @"Why yes, yes it is..." : @"Nope, magic C things are breaking!");
[p release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment