View ProjeQtOr On SourceForge.net
ProjeQtOr - Project Management Tool
Supportez nous sur Capterra
OIN - Open Invention Network
ProjeQtOr free project management software - dateGetWeek js routine - ProjeQtOr

Prochaines sessions de formation

Les prochaines formations et démonstrations sont ouvertes, inscrivez-vous rapidement !

 

Démonstration de ProjeQtOr

(gratuit, sur inscription)

Mardi 23 avril (10h30-12h)

Jeudi 16 mai (16h-17h30)

Jeudi 13 juin (10h30-12h)

 
 

Planifiez avec ProjeQtOr

3 et 4 avril (9h - 12h30)

 
 

Administrez avec ProjeQtOr

10 et 11 avril (9h - 12h30)

 

 

 
 

dateGetWeek js routine

More
31 Oct 2018 08:37 #1 by antonio.grr
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:
* 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.

Please Connexion or Create an account to join the conversation.

More
31 Oct 2018 10:21 #2 by babynus
Replied by babynus on topic dateGetWeek js routine

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)

Babynus
Administrator of ProjeQtOr web site

Please Connexion or Create an account to join the conversation.

More
31 Oct 2018 10:56 #3 by antonio.grr
Replied by antonio.grr on topic dateGetWeek js routine
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

Please Connexion or Create an account to join the conversation.

More
31 Oct 2018 11:04 #4 by babynus
Replied by babynus on topic dateGetWeek js routine
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.

Babynus
Administrator of ProjeQtOr web site

Please Connexion or Create an account to join the conversation.

More
31 Oct 2018 14:50 #5 by antonio.grr
Replied by antonio.grr on topic dateGetWeek js routine
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 <= 4 ? 1 : 55;
Anyway, i think that spinner cna be fixed using the following (ISO standard compatible)
lastWeekOfTheYearTemp = function (year, dowOffset) {
/*
* lastWeekOfTheYearTemp() was developed by Antonio Giarratana:
*
*/
dowOffset = (dowOffset === null) ? 1 : dowOffset; // default dowOffset to 1
// (ISO 8601)
var jan1ThisYear = new Date(year, 0, 1);
var jan1ThisYearDow = jan1ThisYear.getDay() - dowOffset; // the day of week the year begins
jan1ThisYearDow = (jan1ThisYearDow >= 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 && jan1NextYearDow >= 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;


?

Please Connexion or Create an account to join the conversation.

More
31 Oct 2018 14:54 #6 by babynus
Replied by babynus on topic dateGetWeek js routine
We have deployed a fix on V7.2.7 than seems to work fine for 2018=>2019 and 2015=>2016

Babynus
Administrator of ProjeQtOr web site

Please Connexion or Create an account to join the conversation.

Moderators: babynusprotion
Time to create page: 0.040 seconds

Paramétrages de cookies

×

Cookies fonctionnels

Ce site utilise des cookies pour assurer son bon fonctionnement et ne peuvent pas être désactivés de nos systèmes. Nous ne les utilisons pas à des fins publicitaires. Si ces cookies sont bloqués, certaines parties du site ne pourront pas fonctionner.

Session

Veuillez vous connecter pour voir vos activités!

Autres cookies

Ce site web utilise un certain nombre de cookies pour gérer, par exemple, les sessions utilisateurs.