NSDateComponents returns incorrect weeknumber
| Originator: | mkadijk | ||
| Number: | rdar://10318936 | Date Originated: | 20-Oct-2011 09:05 PM |
| Status: | Open | Resolved: | |
| Product: | iPhone SDK | Product Version: | 5.0 |
| Classification: | Serious bug | Reproducible: | Always |
20-Oct-2011 09:05 PM Mathijs Kadijk: Summary: The iOS 5 SDK is returning the wrong weeknumber. The weeknumber is compared to iOS 4 always 1 higher. Steps to Reproduce: 1. Run the following code, build against the iOS 5 SDK NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *dateComponents = [calendar components:NSWeekOfYearCalendarUnit fromDate:[NSDate date]]; NSLog(@"%@", [dateComponents description]); // As of Oct 20, 2011 this prints: 43 Expected Results: Result should be 42. (Similar iOS 4 code will return 42) Actual Results: Result is 43. Regression: This problem occurs always when the application is build against the iOS 5 SDK and when you run it on a device with iOS 5. Notes: There is a workaround; This code will return the correct weeknumber: dateComponents = [[NSCalendar currentCalendar] components:NSWeekOfYearCalendarUnit fromDate:[NSDate date]]; NSLog(@"%@", [dateComponents description]); // Result: 42 See also: https://devforums.apple.com/message/562827
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!