I have 3 variables;
startDate – Wed Apr 12
endDate – Wed Jun 11
timeDuration – 11.00 am from 11.00 pm. (this is a string, 11AM is the start time and 12PM is the end time)
1.) Now, i need to get the current date and time ( [NSDate date] ) and check if the current date is between the startDate and endDate and then check if the current time is between the timeDuration (as in between 11.00am from 11.00pm)
2.) If the current time is between the time duration (as in between 11.00 am from 11.00 pm) I need to calculate the time remaining to the following scenarios;
a.) If the time is 10am, i need to calculate the time to the start time which is 11.00am. (the answer is 1 hour).
b.) If the time is 11.45AM, since the time is greater than the start time (which was 11.00am) i need to calculate the time remaining to the end time (which is 11.00pm).
c.) If the time is 11.45pm, since the time is greater than the end time (which is 11.00pm), i need to print a NSLog saying that ‘Time Exceeded’.
The basic idea is to convert your
startDateandendDateinto actualNSDate‘s and compare them to the current date. Then if the current date is in the proper range, you add the start and end times onto the current date to come up with a specific point in time for the starting and ending times. Once you have those dates, you can use thecompareandtimeIntervalSinceDatemethods of NSDate to get the values that you need: