Forum

dateGetWeek js rout...
 
Notifications
Retirer tout

dateGetWeek js routine

6 Posts
2 Utilisateurs
0 Reactions
2,801 Vu
(@antonio-grr)
Posts: 84
Active Member
Début du sujet
 
[#5519]

Hi.
I think that dateGetWeek routine is wrong. If you try weekSpinner behaviour you will see strange things. I modify that routine this way
dateGetWeek = function (paramDate, dowOffset) {
/*
* getWeek() was developed by Antonio Giarratana:
* http://www.meanfreepath.com
*/
dowOffset = (dowOffset === null) ? 1 : dowOffset; // default dowOffset to 1
// (ISO 8601)
var jan1ThisYear = new Date(paramDate.getFullYear(), 0, 1);
var jan1ThisYearDow = jan1ThisYear.getDay()-dowOffset;
if (jan1ThisYearDow < 0) {
jan1ThisYearDow += 7;
}
var thisDow = paramDate.getDay()-dowOffset;
if (thisDow < 0) {
thisDow += 7;
}
var thisDoY = Math.floor((paramDate.getTime() - jan1ThisYear.getTime() - (paramDate.getTimezoneOffset() - jan1ThisYear.getTimezoneOffset()) * 60000) / 86400000) + 1;
var weeknum = Math.floor((thisDoY + jan1ThisYearDow - 1) / 7) + 1;
return weeknum;
};

Now Spinner seems to work.


 
Posté : 31 Oct AM 10:1010
(@babynus)
Posts: 14952
Membre Admin
 

If you try weekSpinner behaviour you will see strange things.

Can you explain what are the "strange things" ?

In my opinion week spinner (for instance on Timesheet screen) works fine.
But take care that is takes into account ISO definition of week number.
It means week 1 of a year is the first week with 4 days on the given year.
So Week 1 of 2019 is the week that starts on 2018-12-31.

In your algorythm, you concider week 1 as the week with the first monday on the year.
In your case Week 1 is the one that starts on 2019-01-07 (first monday on 2019)


 
Posté : 31 Oct PM 12:1010
(@antonio-grr)
Posts: 84
Active Member
Début du sujet
 

Hi.
Try on the page of Work - weekly Report. As soon as you increase week up 50, you get 1 2019 instead of 51 2018. It's the result of recent patch you added in spinner script; it was
if (this.value>getWeek(31, 12, year) ) {
now
if (this.value>getWeek(31, 12, year) && this.value>50) {
At the moment getWeek(31, 12, 2018) returns 1 as week number !!
In my routine I ignore ISO standard but actually I assume first week the first one containing Sunday ( Italian standard)
I tried dates from jan 1 2019 up to jan 8 2019 and I get week 1 up to 6, week 2 later


 
Posté : 31 Oct PM 12:1010
(@babynus)
Posts: 14952
Membre Admin
 

I think the spinner script should be fixed, not dateGetWeek function.

Possibly we should introduce a parameter to select which is first week of the year, but as long as we don't have it, ISO is the best common format.


 
Posté : 31 Oct PM 13:1010
(@antonio-grr)
Posts: 84
Active Member
Début du sujet
 

The routine should be fixed too : try it for first days in 2016 and you will get 0, as 0 result is not handled. Or you can get 55 instead of 53 (look weeknum = nday = 0 ? jan1ThisYearDow : jan1ThisYearDow + 7);
var jan1NextYear = new Date(year + 1, 0, 1);
var jan1NextYearDow = jan1NextYear.getDay() - dowOffset; // the day of week the year begins
jan1NextYearDow = (jan1NextYearDow >= 0 ? jan1NextYearDow : jan1NextYearDow + 7);
var weeknum = 52;
// if the year starts before the middle of a week
if (jan1ThisYearDow = 4) {
weeknum = 53;
}
return weeknum;
};
and changing spinner script this way
var year = dijit.byId('yearSpinner').get('value');
if (this.value > lastWeekOfTheYear(year,1)) {
dijit.byId('weekSpinner').set('value', 1);
year = parseInt(year) + 1;
dijit.byId('yearSpinner').set('value', year);
} else if (this.value == 0) {
year = parseInt(year) - 1;
dijit.byId('weekSpinner').set('value', lastWeekOfTheYear(year,1));
dijit.byId('yearSpinner').set('value', year);
}
var week = dijit.byId('weekSpinner').get('value') + '';
week = (week.length == 1) ? '0' + week : week;
dojo.byId('periodValue').value = '' + year + week;

?


 
Posté : 31 Oct PM 16:1010
(@babynus)
Posts: 14952
Membre Admin
 

We have deployed a fix on V7.2.7 than seems to work fine for 2018=>2019 and 2015=>2016


 
Posté : 31 Oct PM 16:1010
Share:
Retour en haut