Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Calender weeks not correct at year start/end (Read 6598 times)
Grisu
YaBB Newbies
*
Offline


WPF is cool

Posts: 5
Location: Germany
Joined: Nov 30th, 2011
Calender weeks not correct at year start/end
Nov 30th, 2011 at 10:30am
Print Post  
The scheduler in Monthrange view show the wrong calender weeks at the end of the year.
First I use a german W7 and I use the following Culture settings:
System.Globalization.CalendarWeekRule = FirstFourDayWeek
DateTimeFormatInfo.FirstDayOfWeek = Monday
MindFusion.Scheduling.Wpf.dll 3.1.0.0

To see the problem use the DualView sample and ONLY change the MonthSetting.WeekHeaderStyle = "Left" and the MonthRangeSettings ScrollInterval = "1".
Step forward to the point where you see December 2012 and Januar 2013 at the left side in the calender. The last day of december is shown as calender week 53 but 2012 has only 52 weeks. The first days in Januar are shown also with week 53 and the second week has the week number 2. So there is no week number 1, but a week 53.
December 2011 to Januar 2012 is ok, 2011 has 52 weeks.
2012 to 2013 not ok, 2013 to 2014 not ok,2014 to 2015 not ok,
December 2015 to Januar 2016 is ok, because 2015 has 53 weeks
Thanks
Udo
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Calender weeks not correct at year start/end
Reply #1 - Nov 30th, 2011 at 11:25am
Print Post  
We are relying on the result of the System.Globalization.Calendar.GetWeekOfYear(...) method for the first day of the week (which in the first case is Dec 31, 2012). This method returns 53 for this date and that's what we display in the header.

If you have a suggestions on how to solve this, please let me know.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Grisu
YaBB Newbies
*
Offline


WPF is cool

Posts: 5
Location: Germany
Joined: Nov 30th, 2011
Re: Calender weeks not correct at year start/end
Reply #2 - Nov 30th, 2011 at 11:39am
Print Post  
Hi Meppy,
there are some post for a known problem with the function GetWeekOfYear in .Net. Please see e.g. :
http://blogs.msdn.com/b/shawnste/archive/2006/01/24/iso-8601-week-of-year-format...

I use instead the following code and it worked, too:

CultureInfo currentCulture = CultureInfo.CurrentCulture;
Calendar calendar = currentCulture.Calendar;
int calendarWeek = calendar.GetWeekOfYear(date,
currentCulture.DateTimeFormat.CalendarWeekRule,
currentCulture.DateTimeFormat.FirstDayOfWeek);

if (calendarWeek > 52)
{
date = date.AddDays(7);
int testCalendarWeek = calendar.GetWeekOfYear(date,
currentCulture.DateTimeFormat.CalendarWeekRule,
currentCulture.DateTimeFormat.FirstDayOfWeek);
if (testCalendarWeek == 2)
calendarWeek = 1;
}

Regards,
Udo
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Calender weeks not correct at year start/end
Reply #3 - Nov 30th, 2011 at 3:45pm
Print Post  
We have added a new event to the control - Calendar.QueryHeaderText, which is currently only raised for the week headers of the SingleMonth and MonthRange views. You can handle this event and perform the correct calculations of the week number:

Code
Select All
void calendar_QueryHeaderText(object sender, QueryHeaderTextEventArgs e)
{
      // Perform the calculations here and set the appropriate text to e.Text
      e.Text = calendarWeek.ToString();
} 


We opted not to integrate the workaround directly into the control for several reasons, particularly because the bug will eventually be resolved in the future.

The new version of the component can be downloaded here.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Grisu
YaBB Newbies
*
Offline


WPF is cool

Posts: 5
Location: Germany
Joined: Nov 30th, 2011
Re: Calender weeks not correct at year start/end
Reply #4 - Nov 30th, 2011 at 5:53pm
Print Post  
Hi Meppy,

this works thanks.
But I am wondering how often this new Event is fired.
This new Event will from now on be part of all builds you deliver?
So if I maybe find an other problem/bug and you send me a new version this new event will be included?

Thank,
Regards
Udo
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Calender weeks not correct at year start/end
Reply #5 - Dec 1st, 2011 at 6:57am
Print Post  
Hi Udo,

The new event is raised once for each header cell only when the view is initially rendered or in response to a change in the settings (such as changing the displayed month) which causes the view to be refreshed.

Also, the event will be part of all future builds, including official releases.

Regards,
Meppy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint