Search code examples
iosnsdateisonscalendar

Get calendarweek of an NSDate according ISO 8601


is there a way to get calendarweek of an NSDate according ISO 8601. I think:

Datecomponents *dateComponents = [cal components:(NSWeekOfYearCalendarUnit ) fromDate: testDate ];
int calandarWeek =  [dateComponents weekOfYear];

uses a different algorithm.

ISO definition: CW1 is the first week in the year containing 4 day, CW start on Mondays


Solution

  • I found out. It´s possible to configure the NSCalender:

    [cal setFirstWeekday:2];            //week starts on Monday
    [cal setMinimumDaysInFirstWeek:4];  //first week in the year containing 4 day