NSDateFormatter gives unexpected results with region format set to "United Kingdom" when 24-hour mode is off

Originator:simon
Number:rdar://14812657 Date Originated:22-Aug-2013 10:49 PM
Status:Open Resolved:
Product:iPhone/iPod touch Product Version:iOS 6.1.3
Classification:Serious Bug Reproducible:Always
 
Summary:

The following code:

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZ";
    
    NSDate *now = [NSDate date];
    NSLog(@"%@: %@", dateFormatter.locale.localeIdentifier, [dateFormatter stringFromDate:now]);
    
    dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    NSLog(@"%@: %@", dateFormatter.locale.localeIdentifier, [dateFormatter stringFromDate:now]);
    
    dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"];
    NSLog(@"%@: %@", dateFormatter.locale.localeIdentifier, [dateFormatter stringFromDate:now]);

Gives the following output:

2013-08-22 22:30:33.937 DateTest[5277:60b] en_GB: 2013-08-22T10:30:33 PM+0100
2013-08-22 22:30:33.942 DateTest[5277:60b] en_US: 2013-08-22T22:30:33+0100
2013-08-22 22:30:33.945 DateTest[5277:60b] en_GB: 2013-08-22T22:30:33+0100

Steps to Reproduce:

NB: this can only be replicated on a device, since there is no way to set the iOS 6.1 simulator to use a 12-hour clock while the locale is set to en_GB.

1. Settings > General > International > Region Format, choose United Kingdom
2. Settings > General > Date & Time, turn 24-Hour Time to OFF
3. Start an iOS project in Xcode, paste the above code into your app delegate's -applicationDidBecomeActive: method and run

Expected Results:

en_GB: 2013-08-22T22:30:33+0100
en_US: 2013-08-22T22:30:33+0100
en_GB: 2013-08-22T22:30:33+0100


Actual Results:

en_GB: 2013-08-22T10:30:33 PM+0100
en_US: 2013-08-22T22:30:33+0100
en_GB: 2013-08-22T22:30:33+0100

Note: the same occurs on iOS 7 beta 5, but the PM in the first line is in lower case:

en_GB: 2013-08-22T10:30:33 pm+0100
en_US: 2013-08-22T22:30:33+0100
en_GB: 2013-08-22T22:30:33+0100

Regression:

Unknown

Notes:

n/a

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!