"24-hour time" setting applies to NSDateFormatter

Originator:valexa
Number:rdar://8420218 Date Originated:12-Sep-2010 03:03 AM
Status:Behaves correctly Resolved:
Product:iPad Product Version:3.1
Classification: Reproducible:Always
 
12-Sep-2010 03:03 AM Vlad Alexa:
Summary:

"24-hour time" setting applies to NSDateFormatter

Steps to Reproduce:


NSString *theTime;  
  NSDateFormatter *formatter;

  formatter = [[NSDateFormatter alloc] init];
  [formatter setDateFormat:@"hh:mm aa"];  
  theTime = [formatter stringFromDate:[NSDate date]];
  NSLog(@"%@",theTime);  
  [formatter release];

  formatter = [[NSDateFormatter alloc] init];
  [formatter setDateFormat:@"hh:mm aa"];  
  [formatter setAMSymbol:@"AM"];
  [formatter setPMSymbol:@"PM"];  
  theTime = [formatter stringFromDate:[NSDate date]];
  NSLog(@"%@",theTime);  
  [formatter release];    

//iOS 4+ only
  //theTime = [NSDateFormatter localizedStringFromDate:[NSDate date] dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle];  
  //NSLog(@"%@",theTime);  

  time_t currentTime = time(NULL);
  struct tm timeStruct;
  localtime_r(¤tTime, &timeStruct);
  char buffer[20];
  strftime(buffer, 20, "%I:%m %p", &timeStruct);
  NSString *cTime = [NSString stringWithCString:buffer encoding:NSASCIIStringEncoding];
  NSLog(@"%@",cTime);


Expected Results:

AM from NSDateFormatter too not only strftime

Actual Results:

iOS 3.2

"24-hour time" setting ON
2010-09-12 02:31:18.005 FooBar[13855:207] 02:31
2010-09-12 02:31:18.011 FooBar[13855:207] 02:31
2010-09-12 02:31:18.013 FooBar[13855:207] 02:09 AM 

"24-hour time" setting OFF
2010-09-12 02:30:38.861 FooBar[13848:207] 02:30 AM
2010-09-12 02:30:38.866 FooBar[13848:207] 02:30 AM
2010-09-12 02:30:38.871 FooBar[13848:207] 02:09 AM


iOS 4.1

"24-hour time" setting ON
2010-09-12 02:28:00.981 FooBar[1453:307] 02:28
2010-09-12 02:28:01.049 FooBar[1453:307] 02:28
2010-09-12 02:28:01.098 FooBar[1453:307] 2:28
2010-09-12 02:28:01.112 FooBar[1453:307] 02:09 AM

"24-hour time" setting OFF
2010-09-12 02:29:11.590 FooBar[1460:307] 02:29 AM
2010-09-12 02:29:11.610 FooBar[1460:307] 02:29 AM
2010-09-12 02:29:11.662 FooBar[1460:307] 2:29 AM
2010-09-12 02:29:11.674 FooBar[1460:307] 02:09 AM


OSX emulator
2010-09-12 02:27:03.983 FooBar[17181:207] 02:27 AM
2010-09-12 02:27:03.985 FooBar[17181:207] 02:27 AM
2010-09-12 02:27:03.987 FooBar[17181:207] 2:27 AM
2010-09-12 02:27:03.996 FooBar[17181:207] 02:09 AM

Regression:

NO

Notes:

http://multinc.com/2009/09/27/iphone-sdk-time-bug-for-international-users/

14-Sep-2010 02:05 AM Vlad Alexa:
here you go 

28-Apr-2012 04:17 PM Vlad Alexa:
If it worked correctly why was it fixed/changed in iOS 4.0 ?
I can see it working properly since iOS 4.0 e.g.: the code above now returns 

with "24-hour time" setting ON
2012-04-28 16:10:43.326 FooBar[13177:707] 04:10 PM
2012-04-28 16:10:43.331 FooBar[13177:707] 04:10 PM
2012-04-28 16:10:43.335 FooBar[13177:707] 04:04 PM

with "24-hour time" setting OFF
2012-04-28 16:16:09.321 FooBar[13201:707] 04:16 PM
2012-04-28 16:16:09.325 FooBar[13201:707] 04:16 PM
2012-04-28 16:16:09.327 FooBar[13201:707] 04:04 PM

28-Apr-2012 06:15 PM Vlad Alexa:
However this seems to be restricted to the RELEASE_ARM_S5L8940X kernel of iOS 5.1, another machine with RELEASE_ARM_S5L8930X shows the old behavior

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!