I have a rather weird problem. I live in denmark and here the first week (Week 1) of 2013 starts the 31th of december 2012 and lasts for 7 days - as weeks normally do :)
According to .NET however the 30th of december is Week 52, the 31th is Week 53 and the 1st of January is Week 1.
Week 53 lasts for only one day, and Week 1 for 6 days. Clearly this must be wrong (a week consisting of less than 7 days) and certainly is wrong in danish context. Where the 31th of december is Week 1, NOT Week 53.
The following code illustrates the problem (CurrentCulture is "da-DK")
static void Main(string[] args)
{
//Here I get Monday
DayOfWeek firstDayOfWeek = DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek;
//Here I get FirstFourDayWeek
CalendarWeekRule weekRule = DateTimeFormatInfo.CurrentInfo.CalendarWeekRule;
DateTime date = new DateTime(2012,12,30);
for (int i = 0; i <= 10; i++)
{
DateTime currentDate = date.AddDays(i);
Console.WriteLine("Date: {0} WeekNumber: {1}",
currentDate.ToShortDateString(),
CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(currentDate, weekRule, firstDayOfWeek));
}
Console.ReadLine();
}
Have I done something wrong or is this a bug in .NET ? If the latter - do you have suggestions for calculating weeknumbers correctly ?