PDA

View Full Version : [FIXED][3.1] Date.parseDate problem



mono blaine
19 Dec 2009, 5:07 AM
Executing the following line

Date.parseDate('2009-00-12', 'Y-m-d', true)

gives

Dec 12 2009

where it should be just null. That cannot be a feature, right?

Condor
19 Dec 2009, 5:56 AM
You could fix it by using:

"m = m >= -1? m : Ext.num(def.m - 1, dt.getMonth());",

But I'm for changing:

"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()));",

mono blaine
19 Dec 2009, 6:04 AM
Thanks!

mystix
20 Dec 2009, 2:26 AM
@condor, would it be easier to just check for this particular edge case (the only one i can see actually -- correct me if i'm wrong) instead?


}else if(strict === true && (m < 0 || !Date.isValid(y, m + 1, d, h, i, s, ms))){

we really only need to check the month value in this case because of the addition we're performing on it before passing it to Date.isValid() for further checks.



on 2nd thought, i'd go for @condor's suggestion of switching the checks to use Ext.num() all the way
-- it's simply more foolproof.

hendricd
23 Dec 2009, 11:35 AM
Condor's recommendation is now in SVN-5819.
Thus:

Date.parseDate('2009-00-12', 'Y-m-d', true);

now yields the expected 'null'

@Mystix -- can you throw some more 'twisted' tests at it?