Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
errors in parseDate method with 'F', 'M' and 'j' formats
18/01/2012
19:39
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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 

05/02/2012
14:29
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

parseDate : function(format, date) {
    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

06/02/2012
09:13
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

06/02/2012
10:29
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony,

if one uses formatoptions: { newformat: 'n/j/Y' } the format array will be ['n','j', 'Y'] so the line

tsp[format[k].toLowerCase()] = parseInt(date[k],10);

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 

07/02/2012
11:44
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
41 Guest(s)

Currently Browsing this Page:
1 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information