Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if specific date is daylight savings time or not?

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?

like image 475
Jason Avatar asked May 30 '13 00:05

Jason


People also ask

How do I know if a date is DST or not?

calculateUnit((secDiff-(this. years*(86400*365))-(this. days*86400)-(this. hours*3600)),60); this.

What determines daylight Savings day?

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.


1 Answers

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.

like image 174
borrrden Avatar answered Sep 20 '22 00:09

borrrden