Dienstag, 8. November 2011

Wrong week number in calendar control

Are your European customers complaining about wrong week numbers in calendar controls?

Numbering weeks is different from country to country and therefore information is included in Windows' "locale" settings, which are selected through Control Panel's Region and Language Settings. Control vendors (like DevExpress) use the locale information provided by Windows when displaying week numbers.

Unfortunately, Microsoft doesn't always get it perfectly right. E.g. for locale "de-AT" (Austria) Windows defines the wrong rule "CalendarWeekRule.FirstDay" instead of CalendarWeekRule.FirstFourDayWeek.

To work around this issue you can override your app's locale settings to use the correct rule. I use this code in my main/UI thread to setup the right rule in Austria:


      if (Thread.CurrentThread.CurrentCulture.Name == "de-AT")
      {
        var cultureInfo = new System.Globalization.CultureInfo("de-AT");
        cultureInfo.DateTimeFormat.CalendarWeekRule = System.Globalization.CalendarWeekRule.FirstFourDayWeek;
        Thread.CurrentThread.CurrentUICulture = cultureInfo;
        Thread.CurrentThread.CurrentCulture = cultureInfo;
      }

Keine Kommentare:

Kommentar veröffentlichen