Tag Archives: week

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.