alistairphillips.com

I’m : a web and mobile developer based in the Manning Valley, Australia.


NSDateformatter

I recently had a couple of users email in saying that their copies of My Opal were showing all transactions as having occurred on the 01 January 1970. A bit of a time warp!

After some back and forth it appeared that the issue was only happening to users with certain regional settings - Austria, Germany, UK and Italy - and only if they had switched the default 24 hour clock to 12 hour.

Some searching led me to http://stackoverflow.com/questions/143075/nsdateformatter-am-i-doing-something-wrong-or-is-this-a-bug and https://developer.apple.com/library/mac/qa/qa1480/_index.html where you'll promptly be told to set your locale to en_US_POSIX when doing anything with dates behind the scenes (i.e. not for display to users).

As the Opal system is only in use within Sydney I can safely use the following code snippet when working with records.

[[NSLocale alloc] initWithLocaleIdentifier:@"en_AU"]
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Sydney"]];