PDA

View Full Version : Ext.Date.isValid function isn't working as expected



viniciuscs
2 Feb 2012, 7:17 PM
var date = new Date(2012, 1, 1);
console.log(date.toString());
console.log(Ext.Date.isValid(date.getFullYear(), date.getMonth(), date.getDate()));

date = Ext.Date.add(date, Ext.Date.MONTH, -1);
console.log(date.toString());
console.log(Ext.Date.isValid(date.getFullYear(), date.getMonth(), date.getDate()));


Result:

Wed Feb 01 2012 00:00:00 GMT-0200 (E. South America Daylight Time)
true
Sun Jan 01 2012 00:00:00 GMT-0200 (E. South America Daylight Time)
false


Can someone please explain to me why the second validation fails? thks.

mystix
2 Feb 2012, 10:16 PM
Ext.Date.isValid() checks for a 1-based month-of-year argument, not a 0-based month.
(see http://docs.sencha.com/ext-js/4-0/#!/api/Ext.Date-method-isValid)



var date = new Date(2012, 1, 1);
console.log(Ext.Date.isValid(
date.getFullYear(),
date.getMonth(), // month = 1, i.e. January
date.getDate()
));

date = Ext.Date.add(date, Ext.Date.MONTH, -1);
console.log(Ext.Date.isValid(
date.getFullYear(),
date.getMonth(), // month = 0, i.e. invalid
date.getDate())
);