Reputation: 96323
I can fix that easily enough (set the formatter's locale to en_US_POSIX
); that's not the difficulty.
My difficulty is that I want to create a test case that detects the 12-hour-rewriting behavior. I want to set things up so that when my formatter (which should only ever emit 24-hour date strings) spits out a 12-hour date string, at least one test case fails.
I have an iOS test bundle set for SDK current (currently 6.1), target 5.0. When I run my tests under this target, all of my times are still 24-hour.
I have at least one report of this occurring in the wild, so all I need now is to reproduce it reliably in a test case.
Upvotes: 1
Views: 760
Reputation: 318794
Here's one way to check:
NSString *newFmt = [NSDateFormatter dateFormatFromTemplate:@"HH" options:0 locale:[NSLocale currentLocale]];
if ([newFmt hasPrefix:@"h"]) {
// User in 24-hour locale has iOS device set to 12-hour time
}
This can be tested by running the Settings app and going to General, then International. Set the Region Format to the United Kingdom. Then go to General, Date & Time, and set the time format to 12-hour. Then run this code.
Upvotes: 0