PDA

View Full Version : [CLOSED]IE Ext.util.Format.date BUG



ernst96
6 Feb 2011, 11:23 PM
Can anybody tell my why this:


Ext.util.Format.date('2011-02-22T05:00:00','d-M-Y')

throws the following error in IE 8

Error: 'Date.monthNames[...]' is null or not an object

This works fine in all other browsers.

evant
7 Feb 2011, 1:47 AM
Run this in the console:



Date.parse('2011-02-22T05:00:00')


From the docs:



The value to format (Strings must conform to the format expected by the javascript Date object's parse() method)


Seems like IE chokes on that particular format.

ernst96
7 Feb 2011, 9:46 AM
Hm, so you are saying this is a bug? Seems from the sencha docs that this format should work just fine. I ran


Date.parse('2011-02-22T05:00:00')

from the console and IE8 is producing NaN

This is Ext-3.3.1

Do you have any suggestions to work around this?

Thanks

evant
7 Feb 2011, 12:58 PM
No, it's not a bug, the docs state that the value must be in a format the browser can parse. For whatever reason, IE doesn't support that format.

You can use:



var d = Date.parseDate('2011-02-22T05:00:00', 'c');
Ext.util.Format.date(d, 'd-M-Y');

ernst96
7 Feb 2011, 1:22 PM
Right, I ended up using that. Thank you.

Just curious why would Ext.util.Format.date not utilize Date.parseDate and allow passing a read format? Ext.util.Format.date already attempts that but does not account for the fact that IE is not supporting dash separators for d-m-Y. Same seems to be true for Safari.

Something like this:



date : function(v, format, readFormat) {
if (!v) {
return "";
}
if (!Ext.isDate(v)) {
v = Date.parseDate(v, readFormat || "c");
}
return v.dateFormat(format || "m/d/Y");
},


Anyways, thanks again.