Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find DST (Daylight Savings Time) timestamp using Objective-C/C?

Is there a way to get the specific date (way) when daylight davings begins and ends for each country using C or Objective-C?

In the Mexico, summer time begins on the first Sunday in April at 2:00am, and ends on the last Sunday in October at 2:00am. In many POSIX systems this is written as

M4.1.0/2,M10.5.0/2
(Begins: Month 4, 1st Sunday at 02:00AM, Ends: Month 10, last Sunday at 02:00AM)

I know it is possible to know if daylight savings is currently active using

NSTimeZone* systemTimeZone = [NSTimeZone systemTimeZone];
BOOL dstIsOn = [systemTimeZone isDaylightSavingTime];

and that it is possible to get the time until the next Daylight Savings begins

NSTimeZone* systemTimeZone = [NSTimeZone systemTimeZone];
NSTimeInterval delta = [systemTimeZone daylightSavingTimeOffset];

BUT: How would I go about finding the specific day that the daylight savings begins/ends?

Is there some killer table out there that I have not been able to find?

Any help would be greatly appreciated!

like image 875
Groot Avatar asked Mar 18 '13 09:03

Groot


1 Answers

Yes, there is - you can use [NSTimeZone nextDaylightSavingTimeTransitionAfterDate:] method. This returns an NSDate, which you can use with daylightSavingTimeOffsetForDate to establish what the offset is.

Normally you'd use this to find the next offset, but you can obviously run it more than once with different dates to get a series of upcoming daylight saving changes. There is also a convenience method nextDaylightSavingTimeTransition which will always return the next transition.

like image 148
lxt Avatar answered Oct 21 '22 02:10

lxt