-
29 Jul 2011 11:38 AM #1
Date.createParser creates incorrect parsing method for "n/m/Y H" format
Date.createParser creates incorrect parsing method for "n/m/Y H" format
produces the following result:Code:Date.parseDate('1/02/2015 12', 'n/m/Y H', false)
Mon Mar 02 2015 00:00:00 GMT+0530 (India Standard Time)
(See the month changed to March), and the reason seems to me the faulty parser created by Date.createParser method:
Notice this in the above parsing method:Code:(function(input,strict) { var dt, y, m, d, h, i, s, ms, o, z, zz, u, v, def = Date.defaults, results = String(input).match(Date.parseRegexes[2]); if(results){ m = parseInt(results[1], 10) - 1; m = parseInt(results[2], 10) - 1; y = parseInt(results[3], 10); h = parseInt(results[4], 10); if(u != null){ v = new Date(u * 1000); }else{ dt = (new Date()).clearTime(); y = Ext.num(y, Ext.num(def.y, dt.getFullYear())); m = Ext.num(m, Ext.num(def.m - 1, dt.getMonth())); d = Ext.num(d, Ext.num(def.d, dt.getDate())); h = Ext.num(h, Ext.num(def.h, dt.getHours())); i = Ext.num(i, Ext.num(def.i, dt.getMinutes())); s = Ext.num(s, Ext.num(def.s, dt.getSeconds())); ms = Ext.num(ms, Ext.num(def.ms, dt.getMilliseconds())); if(z >= 0 && y >= 0){ v = new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0); v = !strict? v : (strict === true && (z <= 364 || (v.isLeapYear() && z <= 365))? v.add(Date.DAY, z) : null); }else if(strict === true && !Date.isValid(y, m + 1, d, h, i, s, ms)){ v = null; }else{ v = new Date(y < 100 ? 100 : y, m, d, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0); } } } if(v){ if(zz != null){ v = v.add(Date.SECOND, -v.getTimezoneOffset() * 60 - zz); }else if(o){ v = v.add(Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn)); } } return v; })
I think it should have been:Code:if(results){ m = parseInt(results[1], 10) - 1; m = parseInt(results[2], 10) - 1;
Code:if(results){ d = parseInt(results[1], 10) - 1; m = parseInt(results[2], 10) - 1;--
Rahul Singla
-
29 Jul 2011 11:56 AM #2
This is an immediate fix if others are also having this issue:
Code:Date.parseFunctions['n/m/Y H'] = function(date, strict) { var index = date.indexOf('/'); var d = date.substr(0, index); if(d.length==1) date += '0' + date; return (Date.parseDate(date, 'd/m/Y H', strict)); }--
Rahul Singla
Thank you for reporting this bug. We will make it our priority to review this report.


Reply With Quote