I am dealing with a badly-programmed 3rd party API that is forcing me to massage some date/time data in objective C.
Instead of returning dates as absolute UNIX time stamps in UTC, it returns dates as formatted strings with no time zone information. (It actually turns out, after talking to one of their developers, that they are actually storing the date/time in their database as a string without time zone information, not as a timestamp!) The servers are somewhere in the middle of the US so it's currently on CDT, so theoretically I could just add 'CDT' to the formatted dates and use an NSDateFormatter (yyyy-MM-dd HH:mm:ss zzz
) to construct an NSDate. However, depending on the time of year when the date in question comes from, it could be in CST or CDT.
How can I determine whether daylight savings time was in effect at that particular date, so that I can append the proper time zone and calculate the correct UTC date?
calculateUnit((secDiff-(this. years*(86400*365))-(this. days*86400)-(this. hours*3600)),60); this.
To remedy the situation, Congress passed the Uniform Time Act in 1966, establishing consistent use of Daylight Saving Time within the United States: Clocks were to be set ahead one hour on the last Sunday in April and one hour back on the last Sunday in October.
Well, I don't think there is a correct way to do this. There are APIs for this such as:
[NSTimeZone isDaylightSavingTimeForDate:]
and [NSTimeZone daylightSavingTimeOffsetForDate:]
BUT In the transition from CDT to CST, one hour will be repeated so there is no way of knowing whether it is CDT or CST. Other than that one hour assuming CST and checking for daylight savings time should work. My suggestion is to set whoever wrote this API on fire.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With