NSDateFormatter

Apple has provided some extremely low hanging fruit when it comes to support different regional settings. I have my phone set to use Swedish regional settings, it just makes life easier to have times, days of the week, and numbers all displayed the same way I see them in the world around me. However it does seem to cause a lot of problems when using certain iOS apps. Here is part of a screenshot of my phone today while using Path.

Path 2.5 Screenshot

Path 2.5 Screenshot

You can see that it was 2:16pm when I took the screenshot. You'll notice that the phone displays 24-hour time in the status bar as it's done in Sweden. Then you'll notice the two times coming from Path, 2:16 em. Em stands for eftermiddag (Eng: after midday), had I taken the screenshot a few hours earlier it would have shown fm, förmiddag (Eng: before midday).

Other ways the Swedish region differs from the US one, up until iOS 3 or 4 times were actually displayed with a decimal instead of a colon. I'm not sure on why this changed, but more than one app didn't work right on my phone since it was trying to manage times and math on its own and didn't know how to deal with 14.16. Decimals and commas swap meaning in numbers, in the US you write 1,000,000.00 and in Sweden it is 1.000.000,00 or sometimes 1 000 000,00.

The fix is simple, supports all regions Apple supports and makes your code less fragile. The code smell is this line:

[dateFormatter setDateFormat:@"LLL d, yyyy h:m a"];

If you are calling setDateFormat: and displaying that to the user, you are probably doing it wrong. Instead use the constants Apple provides to make it work, and it will work universally. The above becomes:

[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];

All the information you need can be found in the NSDateFormatter documentation. Also initializing a NSDateFormatter can be expensive, so as appropriate initialize one, use it many times, e.g. displaying a bunch of cells for a table view.

Update: Path fixed their date formatting, I believe it was, or around 2.5.5, certainly around the support for the iPhone 5. My thanks to them, though at this point I've created such an aversion to the app that I'm not sure I will overcome.