iOS 5 NSDateComponents bug

It seems, that there is an issue with iOS5 NSDateComponents NSWeekCalendarUnit property.
It returns one week ahead the current, however it returns the correct number on iOS 4.
You can test it with the following code:
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *weekComponents = [gregorian components:(NSWeekCalendarUnit) fromDate:[NSDate date];
NSInteger weekNr = [weekComponents week]

Update I have tested NSWeekOfYearCalendarUnit or NSWeekWeekOfMonthCalendarUnit (available in iOS 5 only), and they still return incorrect value, so currently the best solution is to check iOS version and modify the number manually.

5 thoughts on “iOS 5 NSDateComponents bug

  1. admin Post author

    No, I did version check and modified the value manually by -1. I hope it will show 2 for 2012 January 1…

  2. admin Post author

    Sorry, I have tested it out, but these values also return the bad week number (current + 1)…

Leave a Reply