I know that there is a data type called NSTimeInterval, but this is in seconds. I want to have an object representation that would be able to represent a time range, say Thursday 21 June 8:00 – Thursday 21 June 9:00. Later on I want to compare the current date/time and check whether it fits within this range. What is the best way to do this?
I know that there is a data type called NSTimeInterval , but this is
Share
I would suggest using two NSDate objects to store the start and end dates. You can easily determine if a date is between them using the
timeIntervalSinceDate:method:You just need to make a class which holds two NSDate objects, making sure the first is before the second, and including this method.
FYI, NSTimeInterval is not a class, its a typedef of double.
Edit
Since you want use these as keys for a dictionary, you could use something similar to this to store and search your data:
Usage:
Example interval class:
Example usage code: