我对时间逻辑不是很好,但想检查用户是否在 2 分钟的时间间隔内使用整数 (INT) 和布尔 (DN) 完成了特定任务。
伪代码是这样的
演绎功能1
如果 INT <= 4 在 2 分钟内然后 -0.5 否则如果 INT > 4 在 2 分钟内然后 -1.0
加法功能2
如果 INT < 3 && DN >= 2 在 2 分钟内然后 +0.5 否则如果 INT < 4 && DN >= 3 在 2 分钟内然后 +0.25
目前我这样做只是为了找出间隔
//time check if more then 2 minutes
#define TIME_INTERVAL -120
-(void)shouldCheckForTime
{
NSString *updateUTCPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"UTCDate"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:updateUTCPath];
if (!fileExists)
{
NSDate *currentDate = [NSDate date];
NSArray *array = [NSArray arrayWithObject:currentDate];
[array writeToFile:updateUTCPath atomically:YES];
NSTimeInterval currentUTCTimeStamp = [[NSDate date] timeIntervalSince1970];
NSLog(@"currentUTCTimeStamp %.0f",currentUTCTimeStamp);
}
NSMutableArray *rawArray = [NSMutableArray arrayWithContentsOfFile:updateUTCPath];
if (rawArray == nil)
{
//return NO;
}
//get date from file UTCDate
NSDate *lastUTCDate = [rawArray objectAtIndex:0];
//NSLog(@"CDTS timeIntervalSince1970 %.0f",[lastUTCDate timeIntervalSince1970]);
// NSLog(@"CDTS timeIntervalSinceNow %.0f",[lastUTCDate timeIntervalSinceNow]);
if ([lastUTCDate timeIntervalSinceNow] < TIME_INTERVAL)
{
//NSLog(@"more then 2 mins");
}
else
{
//NSLog(@"less then 2 mins");
}
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[dateFormatter setDateFormat:@"mm:ss:SS"];
NSDate* firstDate = [dateFormatter dateFromString:@"01:00:00"];
NSDate* secondDate = [dateFormatter dateFromString:@"01:02:00"];
NSTimeInterval timeDifference = [secondDate timeIntervalSinceDate:firstDate];
//NSLog(@"time diff %f",timeDifference);
}
感谢您阅读并感谢任何评论。