[sync-services-developers] Converting a VCal timezone object to an NSTimeZone

Brian M. Criscuolo bcriscuolo at markspace.com
Fri Oct 28 06:12:06 PDT 2005


Jud, it looks as if you have a wealth of information to construct a  
proper time zone. It might require some brute-force matching up, but  
you should be able to get by.

Basically, enumerate [NSTimeZone knownTimeZoneNames]. This will give  
you a long list of all of the OS's time zone names (like US/Pacific  
or America/New York).

For each time zone name, create a time zone: nsTimeZone =  
[[NSTimeZone alloc] initWithName:currentName];

You can then check to see if the [nsTimeZone secondsFromGMT] is equal  
to the TZOFFSET value of your vCal definition, so that you know  
you're in the right direction. If it isn't, continue your enumerator.  
If it is, you'll want to look at secondary data:

For the date that you have (like an event start date), is that in DST?
BOOL isDST = [nsTimeZone isDaylightSavingTimeForDate:eventStartDate];

If that time zone is in DST, does the vCal time zone actually have a  
DST value (many don't, especially if it is equatorial, or in some  
parts of the US)?

Another secondary check is to try to match up the nsTimeZone name or  
abbreviation to the data you have in the vCal TZID. You may want to  
look for substrings, like Pacific or Tijuana, to get even closer to  
an exact match. Otherwise, you might end up taking the first time  
zone (name-wise) alphabetically. For instance, I have a case where  
although the time zone is America/New York, it is the same GMT offset  
as America/Detroit, and since Detroit comes before New York and there  
is no other data to rely on (I just have GMT offset) I have to go  
with Detroit.

You definitely have the data to create a time zone, or to rather use  
the information to find one already defined by the system. The  
biggest check, at least to get you close, is to look at the offsets  
from GMT. They you *need* to look at DST data, as it varies depending  
on what time zone/date it is. You can get closer still by matching  
names.

Good luck with it, and let me know if you need any more info. I've  
been struggling with time zone sync for a while but think I have a  
good solution at this point (doing the above).

b

On Oct 27, 2005, at 5:55 PM, Jud Spencer wrote:

> Does anyone have any experience in constructing an NSTimeZone from  
> scratch?
> I don't see any way to do it. I need to be able to take a TimeZone
> specification from a Vcalendar and create an NSTimeZone from it.
>
> Example spec;
>
> BEGIN:VTIMEZONE
> TZID:Pacific Time (US & Canada); Tijuana
> X-ENTOURAGE-TZID:1
> BEGIN:STANDARD
> DTSTART:20001029T020000
> RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10
> TZOFFSETFROM:-0700
> TZOFFSETTO:-0800
> TZNAME:Standard Time
> END:STANDARD
> BEGIN:DAYLIGHT
> DTSTART:20010401T020000
> RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=4
> TZOFFSETFROM:-0800
> TZOFFSETTO:-0700
> TZNAME:Daylight Savings Time
> END:DAYLIGHT
> END:VTIMEZONE
>
> Does anyone know if this is even possible?
>
> Thanks,
>
> Jud
>
>
> _______________________________________________
> sync-services-developers mailing list
> sync-services-developers at lists.markspace.com
> http://lists.markspace.com/mailman/listinfo/sync-services-developers


********************
Brian M. Criscuolo
Senior Software Engineer
Mark/Space, Inc.
bcriscuolo at markspace.com
<http://www.markspace.com>





More information about the sync-services-developers mailing list