This is a migrated thread and some comments may be shown as answers.

kendo.date.weekInYear returning wrong week number?

4 Answers 217 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rami
Top achievements
Rank 1
Veteran
Rami asked on 17 Nov 2017, 08:09 AM

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?

4 Answers, 1 is accepted

Sort by
0
Rami
Top achievements
Rank 1
Veteran
answered on 17 Nov 2017, 08:11 AM
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
0
Nencho
Telerik team
answered on 20 Nov 2017, 03:15 PM
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.
0
Rami
Top achievements
Rank 1
Veteran
answered on 21 Nov 2017, 09:13 AM

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))

0
Nencho
Telerik team
answered on 23 Nov 2017, 08:25 AM
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.
Tags
General Discussions
Asked by
Rami
Top achievements
Rank 1
Veteran
Answers by
Rami
Top achievements
Rank 1
Veteran
Nencho
Telerik team
Share this question
or