Correct week number in the calendar popup of the schedule view

9 posts, 1 answers
  1. Mihai
    Mihai avatar
    10 posts
    Member since:
    Apr 2013

    Posted 29 Oct 2015 Link to this post

    Hi,

    We're confronted with the following situation on the calendar popup of the schedule view we use in one of our Silverlight applications.

    Depending on the culture, the calendar shows that year 2015 has 52 or 53 weeks. For instance if we switch the culture to France "fr", then there are 52 week, but for German "de" there are 53 weeks (see attached screenshots).

    According to ISO 8601 https://en.wikipedia.org/wiki/ISO_8601#Week_dates year 2015 has 53 weeks because the last Thursday of the year is on 31.12.2015.

    According to the MSDN documentation https://msdn.microsoft.com/en-us/library/system.globalization.calendarweekrule.aspx and this posting http://blogs.msdn.com/b/shawnste/archive/2006/01/24/iso-8601-week-of-year-format-in-microsoft-net.aspx the .NET framework "does not map exactly to ISO 8601".

    Is there a way on how to influence the calendar in the schedule view to adhere to the ISO 8601 for cultures which respect it?

    Is it possible somehow to implement the workaround described in the blog entry mentioned above?

    Is there another reason why it differs between German and French cultures?

    Here is how the number of weeks are by the cultures we tested with:

    EN - US : 52 
    EN - UK : 52 
    DE - DE : 53 
    DE - CH : 53 
    ES : 52 
    FR : 52 
    IT : 53 
    NL : 53 
    CZ : 52 
    PL : 53 
    HU : 52 

     

    Thank you,

    Mihai

  2. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 02 Nov 2015 Link to this post

    Hi Mihai,

    The first week of the year is determined by CalendarWeekRule of the current culture. For DE it is FirstFourDayWeek and for FR it is FirstDay - so as seen on the first screenshot there are 3 days from the first week and that is why the week number is 53. So what I can suggest you would be to simply change the CalendarWeekRule for the FR culture to FirstFourDayWeek and the Calendar will look identical to the one when the culture is DE:

    var cultureInfo = new CultureInfo("fr-FR");
    cultureInfo.DateTimeFormat.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek;

    Hope this helps.

    Regards,
    Kalin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Mihai
    Mihai avatar
    10 posts
    Member since:
    Apr 2013

    Posted 05 Nov 2015 in reply to Kalin Link to this post

    Hi Kalin,

    Thank you for your answer. I did the modification indicated by you and set the FirstFourDayWeek rule specifically for the FR culture, but the calendar from the schedule view control still does not show 53 weeks for the FR culture.

    var availableCultures = new List<CultureInfo>();
     
    ...
     
    var cultureInfo = new CultureInfo(culture);
    if (culture == "fr")
    {
          cultureInfo.DateTimeFormat.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek;
    }
    availableCultures.Add(cultureInfo);

    The version we currently use is 2014.3.1202.1050

    I attached some screen shots.

     

    Thank you and kind regards,

    Mihai

  5. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 09 Nov 2015 Link to this post

    Hello Mihai,

    Please check the attached sample project - when initially set it works as expected. However if you are changing the culture at run time you might need to reset the ControlTemplate of the ScheduleView in order to refresh the control.

    Hope this helps.

    Regards,
    Kalin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Mihai
    Mihai avatar
    10 posts
    Member since:
    Apr 2013

    Posted 11 Nov 2015 in reply to Kalin Link to this post

    Hi  Kalin,

    If I set the culture and week rule initially, on application start, then it works fine just as it works in the sample project you provided.

    However, if the culture is changed at runtime, and this is the scenario which is mostly used in our application, then the calendar does not change as expected even though the CalendarWeekRule is correctly set to FirstFourDayWeek.

    When the culture is changed at runtime, the view containing the ScheduleView control is fully reloaded, the constructor of the view and the constructor of the associated view model are called. If I set a breakpoint in any of them and check the CalendarWeekRule on the CurrentCulture, I find that it's correctly set.

    Is there another way to reset the ControlTemplate? We have a Style for the ScheduleView which sets a customised ControlTemplate for the control.

    Thank you and regards,

    Mihai

  7. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 12 Nov 2015 Link to this post

    Hello Mihai,

    What I can suggest you would be to check the localization example from our online Silverlight demos:
    http://demos.telerik.com/silverlight/#ScheduleView/Localization

    Using the same approach while changing the culture would allow to achieve the desired. For example if you do it on button click:
    private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        var cultureInfo = new CultureInfo("fr-FR");
        cultureInfo.DateTimeFormat.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek;
        Telerik.Windows.Controls.LocalizationManager.DefaultCulture = cultureInfo;
     
        var template = this.ScheduleView.Template;
        this.ScheduleView.Template = null;
        this.ScheduleView.Template = template;
    }

    Please note that you would also need to change the supported cultures setting the project (unload it and then open it for editing) as shown below:
    <SupportedCultures>en;fr</SupportedCultures>

    Hope this helps.

    Regards,
    Kalin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. Mihai
    Mihai avatar
    10 posts
    Member since:
    Apr 2013

    Posted 17 Nov 2015 in reply to Kalin Link to this post

    Hi Kalin,

    I recreated the demo project from http://demos.telerik.com/silverlight/#ScheduleView/Localization and followed your advice to reset the template but unfortunately the use case I need still does not work correctly.

    Please have a look at the attached solution (dropbox link https://www.dropbox.com/s/42xxj4ayrdam76r/ScheduleViewLocalization.zip?dl=0 ). Change the culture to "français" and notice that the number of the weeks for 2015 is still 52 even though the CalendarWeekRule is specifically set to FirstFourDayWeek for this culture.

    Thank you,

    Mihai

  9. Answer
    Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 18 Nov 2015 Link to this post

    Hi Mihai,

    I checked the project - try setting the culture the culture as shown below and it should work as expected:
    supportedCultures.Add(new CultureInfo("fr-FR"));

    if (newCulture.Name == "fr-FR")
    {
        newCulture.DateTimeFormat.CalendarWeekRule = CalendarWeekRule.FirstFourDayWeek;
    }

    Hope this helps.

    Regards,
    Kalin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  10. Mihai
    Mihai avatar
    10 posts
    Member since:
    Apr 2013

    Posted 19 Nov 2015 in reply to Kalin Link to this post

    Hi Kalin,

    Yes, it works fine this way.

    Thank you for your support and patience.

     

    Regards,

    Mihai

Back to Top
DevCraft banner