5

I want to "hardcode" an expiration date into my beta code. Right now I manually calculate a unix date and compare that to the current date time:

 if([[NSDate date] timeIntervalSince1970]>1422748800) mustHalt = TRUE;

I'd like a way of replacing the 1422748800 with a macro that generates the equivalent number for a date 90 days in the future at compile time.

Any suggestions?

Michael Dorner
  • 17,587
  • 13
  • 87
  • 117
JeremyLaurenson
  • 979
  • 2
  • 11
  • 23

1 Answers1

3

The predefined macro __DATE__ is what you need. Here is a SO question related to this. But maybe you want to use a code like this:

    const int daysToExpire = 14;

    NSString *compileDate = [NSString stringWithUTF8String:__DATE__];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"MMM d yyyy"];
    NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [df setLocale:usLocale];
    NSDate *expireDate = [df dateFromString:compileDate];

    bool isExpired = ([[NSDate date] compare:expireDate] == NSOrderedDescending); // decide for it
Community
  • 1
  • 1
Michael Dorner
  • 17,587
  • 13
  • 87
  • 117