Considering that there is no NSTime in Cocoa-Touch (Objective-C on iPhone), and given two times as NSStrings and a timezone as an NSString, how can you calculate whether or not the current LOCAL time is between these two times. Keep in mind that the date in the time strings do NOT matter, and are filled with dummy dates.
For example:
TimeZone: Pacific Time (US & Canada)
Start Time: 2000-01-01T10:00:00Z
End Time: 2000-01-01T17:00:00Z
Local Time: now
How do you confirm whether or not local time is between the time range specified (ensuring to convert the start/end times to the proper timezone first)?
The biggest problem with this seems to come from the fact that the times may span two days (originally they might not, but when you do the timezone conversion, after that they might). So if we’re to ignore the given date information completely, some assumptions have to be made with how to handle these date spans. Your question isn’t exact on how to deal with this (i.e. I don’t know exactly what you’d like to achieve) so here’s just one way to go about it, which might not be exactly what you’re after, but hopefully it will guide you in the right direction:
NSDateobjects, ignoring the date information (result: times are handled such that they’re assumed to be for the same day) and performing the time zone conversionNSDateto the laterNSDateNSDateobjects for “today at the earlier given time” and “yesterday at the earlier given time”NSDates till the current date/time to the time interval between the two given date/timesAlso note that time zone strings in the format you gave (
"Pacific Time (US & Canada)") will not be understood byNSTimeZoneso you’ll need to do some conversion there.Here’s a code example (I wrote this on OS X since I don’t have the iPhone SDK so hopefully all the used APIs will be available on iPhone as well):