5 // Created by murf on 9/12/19.
8 #import <Foundation/Foundation.h>
9 #import "SOSIntervalEvent.h"
10 #import "keychain/SecureObjectSync/SOSInternal.h"
14 interval setting examples:
15 NSTimeInterval earliestGB = 60*60*24*3; // wait at least 3 days
16 NSTimeInterval latestGB = 60*60*24*7; // wait at most 7 days
20 SOSIntervalEvent fooEvent = [[SOSIntervalEvent alloc] initWithDefaults:account.settings dateDescription:@"foocheck" earliest:60*60*24 latest:60*60*36];
23 if([fooEvent checkDate]) {
28 // "schedule" is only used if you think there's a date upcoming you don't want altered
29 // getDate will return the next schedule event date
32 @implementation SOSIntervalEvent
34 - (NSDate *) getDate {
35 return [_defaults valueForKey: _dateDescription];
39 NSDate *theDate = [self getDate];
40 if(theDate && ([theDate timeIntervalSinceNow] <= 0)) return true;
45 NSDate *theDate = SOSCreateRandomDateBetweenNowPlus(_earliestDate, _latestDate);
46 [_defaults setValue:theDate forKey: _dateDescription];
50 NSDate *theDate = [self getDate];
56 -(id)initWithDefaults:(NSUserDefaults*) defaults dateDescription:(NSString *)dateDescription earliest:(NSTimeInterval) earliest latest: (NSTimeInterval) latest {
57 if ((self = [super init])) {
60 _defaults = [[NSUserDefaults alloc] init];
62 _dateDescription = dateDescription;
63 _earliestDate = earliest;