Search code examples
.netvisual-studioisoweek-numbermonthcalendar

MonthCalendar control displaying non ISO-8601 compliant week numbers


I am encountering an issue with the MonthCalendar Windows Form UI Control. With the ShowWeekNumbers property enabled, it shows week 1 of 2016 to be the week containing January 1st, which is on a Friday. This is not compliant with ISO-8601, which states that the first week of the year is the week that contains the year's first Thursday (first 4-day week).

The MonthCalendar control (SysMonthCal32) is part of the Common Control Library (comctl32.dll). It uses the MCS_WEEKNUMBERS style when displaying week numbers. On the Month Calendar Control Styles page of the MSDN site, it provides the following statement in the description of MSC_WEEKNUMBERS: "Week 1 is defined as the first week that contains at least four days." Unfortunately, that is contrary to what I'm experiencing with the control.

Here's a photo of the MonthCalendar control, showing the issue described above.


Solution

  • The calculation for week numbering is determined by the operating system's user locale settings. It can not be influence by modifying the CurrentCulture and CurrentUICulture properties of the main execution thread. As stated by this Microsoft Support article:

    This behavior occurs because the DateTimePicker control and the MonthCalendar control are Microsoft Windows common controls. Therefore, the operating system's user locale determines the user interface of these controls.

    Unfortunately, the operating system's user locale settings can not be set during application runtime. To achieve ISO-8601 compliance, a custom control will be necessary. These culture-aware MonthCalendar and DateTimePicker controls on CodeProject should do nicely.