By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,886 Members | 1,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,886 IT Pros & Developers. It's quick & easy.

Week numbers totally incorrect !!

P: n/a
Hi,

When I use the "Calendar.GetWeekOfYear" function (with "fr-BE" as CultureInfo and Monday as the first day of week) I get :



Friday 31/12/2004 : week = 53

Saturday 01/01/2005 : week = 1

(see code sample here below)



That's very interesting but totally incorrect !! Friday and Saturday of the same week should have the same week number ! Except in DOTNET..

ISO 8601 say : Week 01 of a year is per definition the first week that has the Thursday in this year, which is equivalent to the week that contains the fourth day of January. In other words, the first week of a new year is the week that has the majority of its days in the new year.

So the correct numbers are :

Friday 31/12/2004 : week = 53

Saturday 01/01/2005 : week = 53

Manday 03/01/2005 : week = 1

Is there any Patch for this bug ??



Thanks,



Steph.



Code sample :



CultureInfo myCI = new CultureInfo("fr-BE");

Calendar MyCal = myCI.Calendar;

CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;

DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;



MessageBox.Show(MyCal.GetWeekOfYear(Convert.ToDate Time("31/12/2004"), myCWR, myFirstDOW).ToString());



MessageBox.Show(MyCal.GetWeekOfYear(Convert.ToDate Time("01/01/2005"), myCWR, myFirstDOW).ToString());
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Steph,

That is certainly very odd. However, I suspect that this is by design as the CalendarWeekRule of fr-BE is FirstDay and setting the CalendarWeekRule to FirstDay for nb-NO will return week 1 for 2005.1.1 where it would be week 53 for by default with FirstFourDayWeek.

I'm not familiar with the FirstDay rule and AFAIK it means the week number does not carry over to the next year.
Just a thought.

--
Happy coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #2

P: n/a
I made a quick test (I'm French).

It looks like to me that the rule is incorrect for this culture (as well as
for France).

For now using :

CalendarWeekRule myCWR = System.globalization.FirstForuDayWeek ; //
myCI.DateTimeFormat.CalendarWeekRule; (this is FirstDay)

seems to work. Double check this.

For now it looks like the cultural settings are not correct...

Patrice
--

"Steph." <st***@nomail.com> a écrit dans le message de
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hi,

When I use the "Calendar.GetWeekOfYear" function (with "fr-BE" as
CultureInfo and Monday as the first day of week) I get :

Friday 31/12/2004 : week = 53

Saturday 01/01/2005 : week = 1

(see code sample here below)

That's very interesting but totally incorrect !! Friday and Saturday of the
same week should have the same week number ! Except in DOTNET..

ISO 8601 say : Week 01 of a year is per definition the first week that has
the Thursday in this year, which is equivalent to the week that contains the
fourth day of January. In other words, the first week of a new year is the
week that has the majority of its days in the new year.

So the correct numbers are :

Friday 31/12/2004 : week = 53

Saturday 01/01/2005 : week = 53

Manday 03/01/2005 : week = 1

Is there any Patch for this bug ??

Thanks,

Steph.

Code sample :

CultureInfo myCI = new CultureInfo("fr-BE");

Calendar MyCal = myCI.Calendar;

CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;

DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;

MessageBox.Show(MyCal.GetWeekOfYear(Convert.ToDate Time("31/12/2004"), myCWR,
myFirstDOW).ToString());

MessageBox.Show(MyCal.GetWeekOfYear(Convert.ToDate Time("01/01/2005"), myCWR,
myFirstDOW).ToString());
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.