0

For a project I am working on we need to know the week number which is displayed via a date form field widget in the admin section.

On the front end we also show the week number but we are using a jQuery UI datepicker, however these two datepickers are showing different week numbers. This week starting 15/6/2015 is shown as week 25 in jQuery UI and is week 24 in Magento admin date picker.

After some investigation I have found jQuery is using ISO 8601 week date standards to determine the first week of the year.

I am still not sure what format Magento is using but it seems to have some errors displaying at years end/start when I look ahead years.

I am hoping for some setting or fix that I can implement to bring Magento date picker in line with jQuery UI and ISO 8601, I could do the reverse but prefer to follow ISO 8601 standards.

2 Answers 2

0

After some further investigation I found that both where trying to calculate the week using the ISO 8601 standard. Magento appears to have a bug in how it was calculating it which was caused by a bug in the JS that runs the calendar used in the admin section of magento.

The file is js/calendar/calendar.js on line 1187

cell.innerHTML = date.getWeekNumber();

The calls to get the week number of the first day of the week (default Sunday). However the function 'getWeekNumber' gets the week number of the nearest Thursday which for a Sunday is the Thursday of the previous week.

To fix this I changed this to find the week number of the Thursday of the current line rather than the first day of the week.

var tday = new CalendarDateObject(date);
if(date.getDay() > 4){
  tday.setDate(tday.getDate() + (7 - (date.getDay() - 4)));
} else if (date.getDay() < 4){
  tday.setDate(tday.getDate() + (4 - date.getDay()));
}
cell.innerHTML = tday.getWeekNumber();

As this file is a core file, editing it may be overwritten by a future upgrade of Magento. However I've not yet found a way to fix this without overwriting this js file.

1
  • mark your answer as right answer to help other. Jun 19, 2015 at 1:14
0

Change the parameters in this file js/calendar-setup.js

From

param_default("weekNumbers",true)

To

param_default("weekNumbers",false)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.