kendo.date.weekInYear returning wrong week number?

5 posts, 0 answers
  1. Rami
    Rami avatar
    9 posts
    Member since:
    Sep 2017

    Posted 17 Nov Link to this post

    Hello,

     

    I stumbled onto some behaviour that I think is wrong, but am not sure. In this dojo: https://dojo.telerik.com/eyOJA I have created a small snippet that displays the week number of 31.12.2017. That comes up as 1. I was expecting, depending on the culture, maybe an answer of 52 or 53, but certainly not 1. Am I missing something or is there a bug in the weekInYear?

  2. Rami
    Rami avatar
    9 posts
    Member since:
    Sep 2017

    Posted 17 Nov in reply to Rami Link to this post

    I messed up the link, you can get the idea from it, but here's a new one just in case: https://dojo.telerik.com/iJUyEt
  3. Nencho
    Admin
    Nencho avatar
    1671 posts

    Posted 20 Nov Link to this post

    Hello Rami,

    Actually, the result in the alert is the expected one. The Sun Dec 31 2017 is part of the first week of the 2018. This is so, because by the default a week is considered fron Sunday trough Sunday. In addition to that, the first week of the year is the week that contains that year's first Thursday (='First 4-day week'). This is described in our documentation article regarding the weekInYear method:

    https://docs.telerik.com/kendo-ui/api/javascript/date#methods-weekInYear

    However, you can change that behavior, by passing another parameter to the method (weekStart - described in the article above). Hence, you will achieve the returned 52 number for the week:

    https://dojo.telerik.com/iJUyEt/4

    Hope this information helps.  

    Regards,
    Nencho
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  4. Rami
    Rami avatar
    9 posts
    Member since:
    Sep 2017

    Posted 21 Nov in reply to Nencho Link to this post

    Hello Nencho,

     

    I still think the there is something fishy either in the week number calculated by weekInYear or the documentation. In https://docs.telerik.com/kendo-ui/api/javascript/date#methods-weekInYear there is mention of ISO-8601, which even in the link says that

    "Returns week number of a specific date. According to the ISO-8601 standard, weeks starting on Monday". Furthermore, the link states that "weekStart Number (optional)
    The day number (from 0 (Sunday) to 6 (Saturday)) representing what day of week is considered as a starting point. This parameter is optional because by default Monday (1) is considered as a first day of the week".

     

    So if the default of this optional parameter is 1, why do I have to supply the 1 to it?

     

    Also, why does the link state that the second parameter is a number and then the example passes in a date

    "//Sunday is passed as week start console.log(kendo.date.weekInYear(new Date(2017, 0, 9), new Date(2017, 0, 8))); "?

     

    Also, this still returns 1 for me: kendo.date.weekInYear(new Date(2017, 11, 31, 10, 10, 10), new Date(2017, 11, 25))

  5. Nencho
    Admin
    Nencho avatar
    1671 posts

    Posted 23 Nov Link to this post

    Hello Rami,

    Your observations are absolutely correct. The documentation article on the matter has two issues and they are:
    1. The default value is not 1 but it depends on the culture. In other words,for example if used in US - the default value will be 0 (standing for Sunday).
    2. Indeed the second parameter should be a number (as demonstrated in the provided dojo example).

    Both issues will be address as soon as possible and the documentation will be updated accordingly.

    In addition, I have updated your Telerik Points for pointing those issues out.

    Regards,
    Nencho
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top