日付の週数を計算している最中ですが、System.Globalization.Calendar
2007年と2012年の12月31日(他の年の中でも)に奇妙な結果が返されています。
Calendar calendar = CultureInfo.InvariantCulture.Calendar;
var date = new DateTime(2007, 12, 29);
for (int i = 0; i < 5; i++)
{
int w = calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
Console.WriteLine("{0}\t{1}", date.ToString("dd.MM.yyyy"), w);
date = date.AddDays(1);
}
結果
29.12.2007 52
30.12.2007 52
31.12.2007 53 <--
01.01.2008 1
02.01.2008 1
29.12.2012 52
30.12.2012 52
31.12.2012 53 <--
01.01.2013 1
02.01.2013 1
私の知る限り、2007年と2012年には53週目はないはずですが、その日数は1週目に含める必要があります。この動作を変更する方法はありCalendar
ますか?