Skip to content

Commit

Permalink
fixes in parseDate
Browse files Browse the repository at this point in the history
1) fix the bug where the date format from `$.jgrid.formatter.date.masks`
("ISO8601Long" for example) will be not used.
2) allow to parse **not full date**. For example parsing of "4/16/2015"
by format `"n/j/Y g:i:s A"` in the old code produces invalid date
because the time part will be not specified in the input data. It will
be used now `Math.min(format.length, date.length)` as max index during
parsing . All other fields will be stay defaults. It's clear that it can
have some side effects in case of exotic formats and the dates, but I
suppose that new logic will do produce more correct results as the old
one in the most practical cases.
  • Loading branch information
OlegKi committed Apr 16, 2015
1 parent 6fb09c6 commit 8ffb117
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 296 deletions.
12 changes: 6 additions & 6 deletions js/grid.base.js
Expand Up @@ -630,11 +630,11 @@
return h;
};

if (opts === undefined) {
opts = this.p != null ?
jgrid.getRes(locales[this.p.locale], "formatter.date") || jgrid.formatter.date :
jgrid.formatter.date;
}
opts = $.extend(true, {}, (jgrid.formatter || {}).date,
(this.p != null ?
jgrid.getRes(locales[this.p.locale], "formatter.date") :
{}) || {},
opts || {});
// old lang files
if (opts.parseRe === undefined) {
opts.parseRe = /[#%\\\/:_;.,\t\s\-]/;
Expand Down Expand Up @@ -663,7 +663,7 @@
date = String(date).replace(/\T/g, "#").replace(/\t/, "%").split(opts.parseRe);
format = format.replace(/\T/g, "#").replace(/\t/, "%").split(opts.parseRe);
// parsing for month names and time
for (k = 0, hl = format.length; k < hl; k++) {
for (k = 0, hl = Math.min(format.length, date.length); k < hl; k++) {
switch (format[k]) {
case "M":
// A short textual representation of a month, three letters Jan through Dec
Expand Down

0 comments on commit 8ffb117

Please sign in to comment.