views:

145

answers:

1

G'day All

If you create a date item in the plist editor of Xcode or Apple's standalone plist editor you get something of the form <date>2010-05-29T10:30:00Z</date> which is a nice well formed ISO date at UTC (indicated by the "Z"). Because I'm in timezone UTC +10 when that's read into my app & then displayed I get 8:30 PM out, still good. However if that is a time in my timezone it should be <date>2010-05-29T10:30:00+10</date> (replacing "Z" with my timezone offset). All of my attempts at reading such dates into my iPhone app have had the plist rejected as if it is malformed & editing a plist with such a date in Apple's editors changed the "+10" to "Z" without adjusting the time.

Do others think I'm correct in thinking this is a bug in either plist or Xcode? My feeling is that the implementation of ISO date & time in plist is incomplete.

Cheers, Pedro :)

A: 

It's not a bug in either. In CoreFoundation (and Foundation), all dates are represented in Zulu time, which is why they are serialized that way. The date is then formatted for display based on the timezone of the device that wishes to display it. Although this is an ISO date string, the only valid time zone for CoreFoundation/Foundation is Zulu time.

If, for some reason, you need to track the time zone that any given date was generated in, you should track this as a separate property. If you need to write an XML property list from somewhere else, you must first convert the date to zulu and then write it out (although the documentation clearly specifies that these keys are for debugging aids/readability only and may change in the future). This makes plists a decent way to serialize data between two Cocoa/CoreFoundation applications, but a less suitable way of serializing data between a Cocoa/CoreFoundation app and some other application.

Jason Coco
Pedro
@Pedro I think that you are misunderstanding. All dates are internally based on UTC, so there is no issue. If you have an [NSDate date] reference and you write it to a plist, you will get the correct UTC time written to the plist. So if your locale it is 2010-05-29T10:30:00+10 the actual date written to the plist will be 2010-05-29T00:30:00Z -- the correct time. This solves the time issues because /ALL/ times are in UTC and only translated to the /LOCAL/ timezone for display.
Jason Coco
@Pedro: Actually, I see that you are typing the dates into your plist--so in that case, you must do the conversion to UTC at that time (it is silly to have the computer do it at load time, since all date/time is in UTC in Cocoa). So if your time is 10:30 as in the example, when you type in the date, type 00:30:00Z
Jason Coco
Pedro
@Pedro: Well, plist is not really an open data exchange format, it is their serialization format. Instead of using the date tag, you might just want to use a string tag and then use a date formatter to read the date (this will properly handle everything for you and uses the unicode standards to create the format string). This way you can use a real date like 2010-05-29T10:30:00+10 and be ok.
Jason Coco