In the .Net-Framework there is a known bug when trying to calculate the weeknumber with ISO-8601.
Short-Description: “When determining the week number of a date according to the ISO 8601 standard, the underlying function call to the Oleaut32.dll file mistakenly returns week 53 instead of week 1 for the last Monday in certain years.” (Source: Microsoft)
My Question: Is this bug also ‘included’ in MonoTouch and I have to use the workaround, or is it fixed in MonoTouch? The MonoTouch-API-Reference is not a big help here…
UPDATE: As I was told in the comments I did a few tests on my own. Example-Code follows
DateTime first = new DateTime(1851,12,29);
DateTime second = new DateTime(2011,12,30);
DateTime third = new DateTime(1895,12,30);
System.Globalization.Calendar objCal = System.Globalization.CultureInfo.CurrentCulture.Calendar;
int weekNumberFirst = objCal.GetWeekOfYear (first, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
int weekNumberSecond = objCal.GetWeekOfYear (second, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
int weekNumberThird = objCal.GetWeekOfYear (third, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
Console.WriteLine (weekNumberFirst +" "+weekNumberSecond+" "+weekNumberThird);
Supposed Output: 1 52 1
Actual Output: 53 52 53
But would still be nice, to have some “official statement” for this…
I can confirm the bug exists in the latest MonoTouch versions.
It’s unlikely to be fixed unless Microsoft fix their own implementation (I have not tested it on Windows) since Mono compatibility includes a number a bugs (to easy porting). However it would not be very hard to adjust your code to deal with both a working/buggy code base (so any future change won’t affect you).
Note: This is only a semi-official statement. Official statements from any company will only come from official channels 😉