问题
The issue I have is quite clear. This year, the 28th to 31st of december 2014 fall to 53rd week of 2014. For some reason, NSCalendar is generating the wrong value when I extract the components from the date. Why? Am I missing something?
NSDateComponents *mockTodayComponents = [[NSDateComponents alloc] init];
mockTodayComponents.day = 27;
mockTodayComponents.month = 12;
mockTodayComponents.year = 2014;
NSDate *mockToday = [[NSCalendar currentCalendar] dateFromComponents:mockTodayComponents];
/**************************/
NSDateComponents *weekOfYearComponents = [[NSCalendar currentCalendar] components:NSCalendarUnitWeekOfYear | NSCalendarUnitYear
fromDate:mockToday];
I get this
<NSDateComponents: 0xae7aba0>
Calendar Year: 2014
Week of Year: 1
Printing the calendar gives me
(lldb) po calendar.timeZone
Europe/London (GMT+1) offset 3600 (Daylight)
(lldb) po calendar.calendarIdentifier
gregorian
来源:https://stackoverflow.com/questions/24913712/weekofyear-overflowing-to-1-in-53rd-week-in-gregorian-calendar