Gregorian Calendar - GetWeekOfYear for 2005

  • Thread starter Thread starter bp
  • Start date Start date
B

bp

I'm using the System.Globalization.GregorianCalendar class to calculate
week numbers. My weeks begin on Saturday and follow the "first four
day" rule.

GregorianCalendar cal = new GregorianCalendar();
week = cal.GetWeekOfYear("12/31/2005",
CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Saturday);

GetWeekOfYear() returns "53" for "12/31/2005", even though there are
only 52 weeks in 2005. "12/30/2005" correctly returns "52", and
"1/1/2006" correctly returns "1".

Can someone explain this to me? Is this intended behavior or is this a
bug in the GregorianCalendar class?

Thanks in advance.
 
I'm using the System.Globalization.GregorianCalendar class to
calculate week numbers. My weeks begin on Saturday and follow the
"first four day" rule.

GregorianCalendar cal = new GregorianCalendar();
week = cal.GetWeekOfYear("12/31/2005",
CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Saturday);
GetWeekOfYear() returns "53" for "12/31/2005", even though there are
only 52 weeks in 2005. "12/30/2005" correctly returns "52", and
"1/1/2006" correctly returns "1".

Can someone explain this to me? Is this intended behavior or is this
a bug in the GregorianCalendar class?

Thanks in advance.

Check it on a calendar, looks correct to me.
12/30 is a Friday, the end of the 52nd week.
12/31 is a Saturday, the beginning of the 53rd week (1 day week).
 
The project I'm working on is a fiscal calendar that doesn't provide
for "partial weeks" (ie. a week with less than 7 days). In this case I
want "12/31/2005" to be the first day of fiscal week "1" for 2006. The
first week of 2006 would be the week beginning on "12/31/2005" because
that week contains "4 or more" days in January...
I see now that this is not how the GregorianCalendar works...do you
know if there's another calendar with a GetWeekOfYear() method
supporting this calculation?
Thanks for the response.
 
One way to handle this is check the week of 1/1/2006, and also the DayOfWeek
for 1/1/2006. If it returns 3 or more (wednesday or later), add 1 to the
week count, and thus get the correct fiscal week.
 
Back
Top