NSDateFormatter documentation does not explain exceptions to dateFormat

Originator:amorya
Number:rdar://9080156 Date Originated:3/3/2011
Status:Open Resolved:
Product:Documentation Product Version:
Classification:Serious Bug Reproducible:n/a
 
Summary:
Calling setDateFormat on an NSDateFormatter cannot (always) override user's individual preference for 12 or 24 hour clock. I filed bug 8988715, and was told it works as designed. I request the documentation is updated to explain this. 

Steps to Reproduce:
1. Set iPhone region format to United Kingdom
2. Set iPhone 12/24 hour setting to 12 hour clock
3. Run the following code:

	NSDateComponents *comps = [[NSDateComponents alloc] init];
	[comps setDay:6];
	[comps setMonth:5];
	[comps setYear:2004];
	[comps setHour:14];
	[comps setMinute:49];
	[comps setSecond:2];
	NSCalendar *gregorian = [[NSCalendar alloc]
							 initWithCalendarIdentifier:NSGregorianCalendar];
	[gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
	NSDate *date = [gregorian dateFromComponents:comps];	
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setTimeZone: [NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
	[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];  	
	NSString *dateOut = [dateFormatter stringFromDate:date];	
	NSLog(@"Date: %@", dateOut);


Expected Results:
Date: 2004-05-06 14:49:02

Actual Results:
Date: 2004-05-06 02:49:02 PM

Notes:
* In the unicode "Locale Data Markup Language", the character "H" is described as "Hour [0-23]".
* In the NSDateFormatter documentation for method "setDateFormat", we're told to "See Data Formatting Guide for a list of the conversion specifiers permitted in date format strings".
* In the Data Formatting Guide, under "Date Formatters" ->"Formatter Styles", we're told that "If you specify your own format string, you lose user-configurability"
* My test case shows that user configurability is not lost when I specify my own format string, at least for the 12/24 hour clock setting
* Apple's response to bug 8988715 suggests that this behaviour is by design
* Hence the documentation is wrong: there should be a note both in the NSDateFormatter documentation and the Data Formatting Guide that "The format string uses the format patterns from the Unicode standard, except for the character H, which if no locale is set on the NSDateFormatter, is interpreted as the hour in either [0-23] or [1-12] depending on user's 12/24 hour clock preference. If a locale is set on the NSDateFormatter, this character behaves as in the Unicode standard."

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!