PDA

View Full Version : Problem datefield format 'm/Y'



maxbsousa
1 Feb 2012, 6:18 AM
When the computer's date is January 31 of any year, it happens a bug in the 'datefield' when the attribute 'format' is 'm/Y'. If you select any day of February, it changes to 31 March. This happens all the months that do not end with 31 (February, April, June, September and November). In testing, I changed the date of my machine to 31/01/2011. Can anyone help? Following is the code used.

{
xtype: 'datefield',
fieldLabel: 'Month/Year',
format: 'm/Y',
allowBlank: false,
listeners: {
change: function(field, newValue, oldValue){
alert(newValue);
alert(field.getValue().format('d/m/Y'));
alert(field.getValue().format('m/Y'));
}
}

mitchellsimoens
1 Feb 2012, 6:47 AM
The issue is that month 02 is actually that of March... months start at 0. Native javascript:

new Date(2012, 02)

Will give you March 01 2012

maxbsousa
1 Feb 2012, 7:49 AM
Hello, thanks for the reply.
The format 'm/Y' returns:
'm': Numeric representation of a month, with leading zeros (01 to 12)
'Y': A full numeric representation of a year, 4 digits (Examples: 1999 or 2003)
To test:
- Change the date of your system, for example, January 31, 2011.
- Create a date field as the code I posted.
- Select any day in the calendar month of February 2011.
The value of the field should be shown in the '02/2011'. Right? But it shows '03/2011' which corresponds to the month of March. If I selected February because it showed in March?
Do you understand the problem now? Is it a bug? Is there any override to correct this behavior?
Thank you again.

michaelbdavid
30 Jan 2014, 11:51 AM
Hello, thanks for the reply.
The format 'm/Y' returns:
'm': Numeric representation of a month, with leading zeros (01 to 12)
'Y': A full numeric representation of a year, 4 digits (Examples: 1999 or 2003)
To test:
- Change the date of your system, for example, January 31, 2011.
- Create a date field as the code I posted.
- Select any day in the calendar month of February 2011.
The value of the field should be shown in the '02/2011'. Right? But it shows '03/2011' which corresponds to the month of March. If I selected February because it showed in March?
Do you understand the problem now? Is it a bug? Is there any override to correct this behavior?
Thank you again.


I've seen the same behavior above, was a solution for this issue this ever found? Seems that if you change the date format as mentioned above to 'm/Y' for some reason date field converts to Feb to March. If you leave date format as default 'm/d/Y' everything works fine.