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
DateFormat works wrong if the source format contains 'j', 'n', 'F', 'M', 'A' or 'a'
09/04/2012
20:38
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony,

I described before here the same bug in parseDate method defined in grid.base.js module. Unfortunately there are code dupplicates in jqGrid and the same bug exist in $.fmatter.util.DateFormat method defined in the jquery.fmatter.js module. If srcformat definition contains j, n, F, M, A or a formats the current code of DateFormat method will interpret the input data in the wrong way. The problem is more serious because DateFormat method will be used inside of $.unformat.date (see here). So if newformat contains jnFMA or a formats the unformatting works incorrectly.

To fix the bug one should do the following:

1) declare afmt and h12to24 exactly like in parseDate method. For example one can add the correcsponding likes before the line dateFormat=["i18n"]:

timestamp=0, dM, k,hl,
afmt = $.jgrid.formatter.date.AmPm,
h12to24 = function (ampm, h) {
    if (ampm === 0){ if (h === 12) { h = 0;} }
    else { if (h !== 12) { h += 12; } }
    return h;
},

dateFormat=["i18n"]; 

2) modify the body of the for-loop

for(k=0,hl=format.length;k<hl;k++){
    if (format[k] === 'M') {
        dM = $.inArray(date[k],dateFormat.i18n.monthNames);
        if(dM !== -1 && dM < 12){
            date[k] = dM+1;
            ts.m = date[k];
        }
    } else if (format[k] === 'F') {
        dM = $.inArray(date[k],dateFormat.i18n.monthNames);
        if(dM !== -1 && dM > 11){
            date[k] = dM+1-12;
            ts.m = date[k];
        }
    } else if (format[k] === 'a') {
        dM = $.inArray(date[k],afmt);
        if(dM !== -1 && dM < 2 && date[k] == afmt[dM]){
            date[k] = dM;
            ts.h = h12to24(date[k], ts.h);
        }
    } else if (format[k] === 'A') {
        dM = $.inArray(date[k],afmt);
        if(dM !== -1 && dM > 1 && date[k] == afmt[dM]){
            date[k] = dM-2;
            ts.h = h12to24(date[k], ts.h);
        }
    } else if(date[k]) {
        ts[format[k].toLowerCase()] = parseInt(date[k],10);
    }
}

3) One should add the lines

if(ts.j !== undefined) { ts.d = ts.j; }
if(ts.n !== undefined) { ts.m = parseInt(ts.n,10)-1; }
 

before the line

timestamp = new Date(ts.y, ts.m, ts.d, ts.h, ts.i, ts.s, ts.u);

which create the timestamp using m and d properties of ts and not from j and n add which can be set previously by parsing for example the US date format.

The best way will be of cause to introduce common function which will be used by both parseDate and DateFormat methods, but in any way one should fix the bug.

Best regards
Oleg 

10/04/2012
08:56
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello Oleg,

Thanks as always.

You are absolutley right.

I definitley will leave this for the next release  - i.e to have only one parseDate function.

Regards

Tony

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/04/2012
14:58
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony,

I examined the code of parseDate method or the above code in case of usage of 'a' and 'A' and it seems me wrong. Why the code of 'a' and 'A' should be different at all? Additionally the grid.locale-en.js defines $.jgrid.formatter.date.AmPm as ["am","pm","AM","PM"]. So the format 'a' and the input with both "am" and "pm" will produce the same (??!!) results because of the usage of dM < 2 in the code.

There are some other common problems in language files. For example the grid.locale-en.js uses

number : {decimalSeparator:".", , thousandsSeparator: " ", ...},
currency : {decimalSeparator:".", thousandsSeparator: " " , ...}

instead of

number : {decimalSeparator:".", , thousandsSeparator: ",", ...},
currency : {decimalSeparator:".", thousandsSeparator: "," , ...} 

Additionally in the same grid.locale-en.js are defined newformat: 'd/m/Y' and ShortDate: "n/j/Y" where 'n' represents month and 'j' represents the day, without leading zeros. Different english dialects has different oder of month and day in the short day, but one should use newformat and ShortDate which corresponds one format. I suppose that one wanted to use en-US locale. So one should fix newformat to "n/j/Y".

In the same way another very common language file grid.locale-es.js defines $.jgrid.formatter.date.newformat as 'd-m-Y'ShortDate as "n/j/Y" (month/day/Year), AmPm : ["am","pm","AM","PM"]ShortTime as "g:i A" and so on. On the other side the correct oder in Spanish is day/month/year. Somewhere are used day-month-year format instead of day/month/year day/month/year, but nowhere "n/j/Y" (month/day/Year). Additionally the name of the month isn't capitalize (see here for example) like it's in grid.locale-es.js.

Another important part of grid.locale-es.js as the usage of AmPm and 'A' format in times. If one examines different sublocales of ES locale one will find no country where the format will be used. Either one uses 24 hours time format (like in es-ES) or the format 'a' where the "am" and "pm" will be encoded as "a.m." and "p.m." (see here for example inclusive the usage of 'tt' and no 'TT').

It's interesting that the currect code of jqGrid can't process AmPm : ["a.m.","p.m.","A.M.","P.M."]. One uses date.split(/[\\\/:_;.,\t\T\s-]/) (see here and here). The the "p.m." in the input text like "08/04/2012 08:42 p.m." will splitted in separate "p" and "m". Comparing of "p" with "p.m." will fail and the time will be wrong interpreted as "a.m."

My suggestion is:

  • first of all fix the most important clear bugs in grid.locale-en.js and grid.locale-es.js. One can use 24 time format (like in es-ES) because the current code not allow to use "p.m." and "a.m.".
  • to fix parsing of AM and PM to alow the usage of "p.m." and "a.m."
  • to consider to use new (already is not so new) format of the dates and times of JavaScript instead of or additional to PHP format. One can introduce new option: dateFormat ('PHP' or not).
  • to consider in the future to use globalization and localization plugin for date, time, number and currency formats.

Best regards
Oleg 

12/04/2012
11:52
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello Oleg,

As you can imagine I do not have connectuon to these. They are developed from other users, so I must trust them by default, since english is not my primary language.

Also the "AM" and "am" are again developed from other users. If I remember there is git commit on this - will search on it.

Kind Regards

Tony

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.

12/04/2012
19:47
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony,

probably I should not write many things in one post. You answerd only on my last suggestion and not commented the previous one.

First of all I think one should fix mostly common used locale files like grid.locale-en.js. I posted the pool request with some changes. I added more comments in the code to make othrer people easy to make correct translation of grid.locale-en.js to another languages. The file grid.locale-en.js seems be created by you.

Probably one should start to minimize the language files like it was in previous versions of jqGrid.

Tony, could you explain my why parseDate method produce different values for parsing of date using 'a' and 'A' format (see the lines)? Is the case of the input 'am' or 'AM' should be so important that one should produce different Date results? Moreover the parting of the input string with "pm" by 'a' formatter seems to me buggy. Could you confirm the bug?

Best regards
Oleg

P.S. Other things we can disscuss later. 

26/09/2012
22:15
Avatar
earachefl
Member
Members
Forum Posts: 10
Member Since:
04/01/2012
sp_UserOfflineSmall Offline

I've been following this thread for a while as I've never been able to get May dates coming back from Oracle to NOT be formatted as January dates. Oracle datetime format is "F, d Y H:i:s", and I added that as an option to the masks option in locale.en.us. While testing Tony's changes above, I found that in DateFormat (and ParseDate), in the block

 } else if (format[k] === 'F') {

  dM = $.inArray(date[k],dateFormat.i18n.monthNames);

  if(dM !== -1 && dM > 11){

date[k] = dM+1-12;

ts.m = date[k];

}

the dM variable is being set to 4, because "May" exists in both position 4 and position 16 in the monthNames array. So in this instance, ts.m never gets changed from its default value of 0, and May dates get set to January.

I've hacked it like so:

} else if (format[k] === 'F') {

  dM = $.inArray(date[k],dateFormat.i18n.monthNames);

  if(dM === 4){dM = dM+12;}

  if(dM !== -1 && dM > 11){

     date[k] = dM+1-12;

     ts.m = date[k];

  }

but I imagine that longterm you'll figure out a better solution.

27/09/2012
15:49
Avatar
tony
Sofia, Bulgaria
Moderator
Members

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

Hello,

Thanks. Always I think that we need to use only one dateformat function.

Currently we  have parseDate in base grid ans DateFormat in formatter. The do the same think.

Will see what I can do these days.

Regards

Tony

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:
50 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