PDA

View Full Version : [CLOSED-1098] asDate problem??



drshelper
2 Jul 2010, 10:34 AM
I was having a problem with addSorted to add a record to a grouping store where the sort field (not the group field) was a date. I stepped through the code and found that asDate in ext-all.js (3.2.1) starts with this code:



asDate : function(s) {
if(!s){
return 0;
}


and that since s is aa Date it was always returning 0. It seems to me that code was looking for a null or somesuch calue and that this should be:



asDate : function(s) {
if( s == null)
return 0;


and when I made this change the addSorted starting working. Is this a bug or am I misunderstanding something.

Thanks in advance.

evant
6 Jul 2010, 3:20 AM
I don't believe it's a bug, no.

The argument passed should be either

a) A date object
b) A string that can be parsed as a date.

So, it checks if the value isn't "falsey" (false, null, undefined, 0, empty string) and then continues. This is the correct behaviour, none of those can be parsed as dates.

Condor
6 Jul 2010, 4:02 AM
Besides that, your suggested change has absolutely no effect, because in javascript:

(!s) === (s == null)

drshelper
7 Jul 2010, 11:19 AM
It seems the code was passing in an empty string so there was a match. The asDate is being called by extjs to sort a grouping store. If I leave the original code (!s) then the sort comes out wrong. If I make the change I have above, the sort works.

evant
7 Jul 2010, 5:03 PM
What should Date.parse('') return? Definitely not a bug.

drshelper
7 Jul 2010, 5:32 PM
Found the issue. I had something of type "date" and not a Date object. Sigh. Thanks for the help.