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

Does WeekInYear method consider browser local

1 Answer 35 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Kumeri
Top achievements
Rank 1
Iron
Veteran
Kumeri asked on 07 May 2019, 01:17 PM

Hi, 

i would like to know whether the logic in kendo.date.weekInyear() method consider the browser local when calculating the week number. 

Because the first day of the first week does not always fall on the first day of the year
For example, in the US, the week that contains Jan 1 is always the first week. In the US, weeks also start on Sunday. If Jan 1 was a Monday, Dec 31 would belong to the same week as Jan 1, and thus the same week-year as Jan 1. Dec 30 would have a different week-year than Dec 31.

And i know that we can pass a parameter to kendo.date.weekInyear() method for weekStart(number between 0 to 6), If you consider browser local in method logic, how ti will behave once we also input weekStart as a paramter?

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 09 May 2019, 10:46 AM
Hi,

Тhe logic in the kendo.date.weekInyear() method considers the Kendo Culture, which has been configured for the current page. It does not take into account the browser / machine culture. That is why, if you use different Kendo Culture (which is also responsible for the first day of the week configuration), you may end up with different results. Here you could find a small sample demonstrating that. When using the ​bg-BG culture, 1st of  January 2017 will be reported to belong to the 52nd week of year 2016. With the default culture (en-US), it will be reported to belong to the 1st week of year 2017. The difference comes from the fact that the Kendo implementation follows the ISO-8601 standard, according to which the first week of the year is the week that contains that year's first Thursday (='First 4-day week').

Therefore, for the Bulgarian culture, in which the first day of the week is Monday, 1st of January 2017 will be the last day of a week. That week will hold only one day from the year 2017. Therefore, it will be considered to belong to the previous year (2016) and it will be its last week.

The en-US culture, however, has Sunday as its first day. Therefore, 1st of January will belong to the week 1-7th January 2017. There are 7 days of the new year in that week (7 >= 4). That is why, it will be the first week of the year.

The first day of the week can be overridden by using the second parameter of the method call. This way, the following call:
kendo.date.weekInYear(new Date(2017, 0, 1), 0);

will always return 1, independent from the Kendo Culture that is being used.

Regards,
Veselin Tsvetanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Scheduler
Asked by
Kumeri
Top achievements
Rank 1
Iron
Veteran
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or