Forum
19:39
10/08/2009
Hello Tony,
during writing of the answer I found some small bugs in the parseDate method with 'F', 'M' and 'j' formats. To fix the problem one should add additional lines in three places which I marked below fett:
...
for(k=0,hl=format.length;k<hl;k++){ if(format[k] == 'M') { dM = $.inArray(date[k],dfmt); if(dM !== -1 && dM < 12){ date[k] = dM+1; tsp.m = date[k]; } } if(format[k] == 'F') { dM = $.inArray(date[k],dfmt); if(dM !== -1 && dM > 11){ date[k] = dM+1-12; tsp.m = date[k]; } } if(format[k] == 'a') { dM = $.inArray(date[k],afmt); if(dM !== -1 && dM k< 2 && date[k] == afmt[dM]){ date[k] = dM; tsp.h = h12to24(date[k], tsp.h); } } if(format[k] == 'A') { dM = $.inArray(date[k],afmt); if(dM !== -1 && dM > 1 && date[k] == afmt[dM]){ date[k] = dM-2; tsp.h = h12to24(date[k], tsp.h); } } if(date[k] !== undefined) { tsp[format[k].toLowerCase()] = parseInt(date[k],10); } } tsp.m = parseInt(tsp.m,10)-1; var ty = tsp.y; if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;} else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;} if(tsp.j !== undefined) { tsp.d = tsp.j; } } return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s, tsp.u);
One can use the demo to verify that after the modification the filtering work corrct.
Best regards
Oleg
14:29
10/08/2009
Hello Tony,
it's a pity that the bug still not fixed in the jqGrid. The easy way to test the problem would be define jqGrid with local data and the "Search" button in the navigator. The date from the searching dialog will be parsed with respect of formatoptions.newformat opetion of the colModel. If one would use formatter: 'date', formatoptions: { newformat: 'n/j/Y' } or formatter: 'date', formatoptions: { newformat: 'ShortDate' } the date will be wrong parsed currently.
I can extend the bug fix to include support of 'n' format and the different "name" forms like 'ShortDate', 'ISO8601Short' and so on. My current suggestion to fix the code of parseDate is the following
var tsp = {m : 1, d : 1, y : 1970, h : 0, i : 0, s : 0, u:0},k,hl,dM, regdate = /[\/:_;.,tTs-]/;
if(date && date !== null && date !== undefined){
date = $.trim(date);
date = date.split(regdate);
if ($.jgrid.formatter.date.masks[format] !== undefined) {
format = $.jgrid.formatter.date.masks[format];
}
format = format.split(regdate);
var dfmt = $.jgrid.formatter.date.monthNames;
var afmt = $.jgrid.formatter.date.AmPm;
var h12to24 = function(ampm, h){
if (ampm === 0){ if (h === 12) { h = 0;} }
else { if (h !== 12) { h += 12; } }
return h;
};
for(k=0,hl=format.length;k<hl;k++){
if(format[k] == 'M') {
dM = $.inArray(date[k],dfmt);
if(dM !== -1 && dM < 12){
date[k] = dM+1;
tsp.m = date[k];
}
}
if(format[k] == 'F') {
dM = $.inArray(date[k],dfmt);
if(dM !== -1 && dM > 11){
date[k] = dM+1-12;
tsp.m = date[k];
}
}
if(format[k] == 'a') {
dM = $.inArray(date[k],afmt);
if(dM !== -1 && dM < 2 && date[k] == afmt[dM]){
date[k] = dM;
tsp.h = h12to24(date[k], tsp.h);
}
}
if(format[k] == 'A') {
dM = $.inArray(date[k],afmt);
if(dM !== -1 && dM > 1 && date[k] == afmt[dM]){
date[k] = dM-2;
tsp.h = h12to24(date[k], tsp.h);
}
}
if(date[k] !== undefined) {
tsp[format[k].toLowerCase()] = parseInt(date[k],10);
}
}
tsp.m = parseInt(tsp.m,10)-1;
var ty = tsp.y;
if (ty >= 70 && ty <= 99) {tsp.y = 1900+tsp.y;}
else if (ty >=0 && ty <=69) {tsp.y= 2000+tsp.y;}
if(tsp.n !== undefined) { tsp.m = parseInt(tsp.n,10)-1; }
if(tsp.j !== undefined) { tsp.d = tsp.j; }
}
return new Date(tsp.y, tsp.m, tsp.d, tsp.h, tsp.i, tsp.s, tsp.u);
}
I can add that the 'S' format are still not supported in the parseDate. The bold lines in the above code are the lines which I suggest to add to fix the existing bug.
Best regards
Oleg
09:13
Moderators
30/10/2007
Hello Oleg,
Not sure what you want to do, but in you code tsp.n ans tsp.j are always undefined
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
10:29
10/08/2009
Hello Tony,
if one uses formatoptions: { newformat: 'n/j/Y' } the format array will be ['n','j', 'Y'] so the line
will have format[k]='n' and then 'j'. So the tsp.n and tsp.j will be set, but the current code will uses initial tsp.d and tsp.m.
If you will debug the searching filtering by date with the formatoptions: { newformat: 'n/j/Y' } you will see that the day or the month of the date typed in the search field will be decoded wrong in the current code. The usage of formatoptions: { newformat: 'ShortDate' } will produce even the wrond year.
Best regards
Oleg
11:44
Moderators
30/10/2007
Sorry Oleg,
You are right. Little busy these days.
Will be fixed.
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
40 Guest(s)
Currently Browsing this Page:
2 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66