Week numbers totally incorrect !!

S

Steph.

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.ToDateTime("31/12/2004"), myCWR, myFirstDOW).ToString());



MessageBox.Show(MyCal.GetWeekOfYear(Convert.ToDateTime("01/01/2005"), myCWR, myFirstDOW).ToString());
 
L

LOZANO-MORÁN, Gabriel

CalendarWeekRule myCWR = CalendarWeekRule.FirstFourDayWeek;
Indicates that the first week of the year starts on the first day of the
year and ends before the following designated first day of the week.

CalendarWeekRule myCWR = CalendarWeekRule.FirstFourDayWeek;
Indicates that the first week of the year is the first week with four or
more days before the designated first day of the week.

CalendarWeekRule myCWR = CalendarWeekRule.FirstFullWeek;
Indicates that the first week of the year begins on the first occurrence of
the designated first day of the week on or after the first day of the year.

No need to say what the default is for culture fr-BE :)

Gabriel Lozano-Morán


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.ToDateTime("31/12/2004"), myCWR,
myFirstDOW).ToString());

MessageBox.Show(MyCal.GetWeekOfYear(Convert.ToDateTime("01/01/2005"), myCWR,
myFirstDOW).ToString());
 
?

=?iso-8859-1?Q?LOZANO-MOR=C1N=2C_Gabriel?=

What you can also do is use your Windows settings by using the following constructor for CultureInfo (passing true as second param)
CultureInfo myCI = new CultureInfo("fr-BE", true);

Gabriel Lozano-Morán
 
S

Steph.

THANK-YOU !!!! It works correctly now !

I was thinking that by setting the correct CultureInfo the Calendar rule was automaticaly adapted ... bug was in my head !

Steph.


CalendarWeekRule myCWR = CalendarWeekRule.FirstFourDayWeek;
Indicates that the first week of the year starts on the first day of the
year and ends before the following designated first day of the week.

CalendarWeekRule myCWR = CalendarWeekRule.FirstFourDayWeek;
Indicates that the first week of the year is the first week with four or
more days before the designated first day of the week.

CalendarWeekRule myCWR = CalendarWeekRule.FirstFullWeek;
Indicates that the first week of the year begins on the first occurrence of
the designated first day of the week on or after the first day of the year.

No need to say what the default is for culture fr-BE :)

Gabriel Lozano-Morán


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.ToDateTime("31/12/2004"), myCWR,
myFirstDOW).ToString());

MessageBox.Show(MyCal.GetWeekOfYear(Convert.ToDateTime("01/01/2005"), myCWR,
myFirstDOW).ToString());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top