I am working on an iphone app for class and my group is having some time trouble.
The idea we are working with is that we have a scheduled event (say 2:00pm) and we want to know if we are within a certain amount of time from the scheduled time (say +/- 15 minutes). So for this example if the event was at 2pm, if this event was called from 1:45-2:15pm the method would return true/yes, and otherwise, it would return false/no.
I know how to current time/date, but how do I do the part with checking to see if it is within a certain range of time from the event time? ?
So what I am going for would be a method similar to the following with currentTime getting a NSDate object for the current time and classStartTime getting a NSDate object for the start time of the class:
- (BOOL)dateInRange:(NSDate*)currentTime inRangeOf:(NSDate*)classStartTime
{
if([currentTime <= [classStartTime dateByAddingTimeInterval:60*15]] && [currentTime >= [classStartTime dateByAddingTimeInterval:-(60*15)]])
{
return TRUE;
}
else{
return FALSE;
}
}
I know this doesn't work. How do I get the comparison part of the if statement to work properly