WeekOfYear overflowing to 1 in 53rd week in gregorian calendar?

别说谁变了你拦得住时间么 提交于 2021-02-10 23:31:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!