You found a bug! We've classified it as
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
Sencha Premium Member
Ext.Date.parse "M Y" returns wrong date on certain dates
To reproduce, set your computers date at the end of a month with 31 days. (Example: May 31st)
Months with less then 31 days:
Ext.Date.parse("Jun 2012","M Y")
Sun Jul 01 2012 00:00:00 GMT-0700 (Pacific Daylight Time)
Ext.Date.parse("Feb 2012","M Y")
Fri Mar 02 2012 00:00:00 GMT-0800 (Pacific Standard Time)
Months with 31 days:
Ext.Date.parse("Aug 2012","M Y")
Fri Aug 31 2012 00:00:00 GMT-0700 (Pacific Daylight Time)
Ext Premium Member
I figured it out, EJ. This occurs because the parser tries to figure out the day of month in this order:
1.) try to parse the day of month from the input // <-- null in this scenario
2.) look for the default day of month in Ext.Date.defaults.d // <-- undefined unless you set it
3.) inherit today's day of month // <-- 31 in this scenario
Then, when it finally tries to construct the date object, the 31 carries you into the next month. Boo. But it looks like we can set our own Ext.Date.defaults as follows:
I want to suggest that this behavior should be changed because it's not obvious and could easily cause bugs in software built using Ext. Isn't the day defaulting to 1 if unspecified a more reasonable and expected result than having the result dependent on when you tried to parse the date?
console.log(Ext.Date.parse('Feb 2012', 'M Y'));
// Fri Mar 02 2012 00:00:00 GMT-0800 (Pacific Standard Time)
Ext.Date.defaults.d = 1;
console.log(Ext.Date.parse('Feb 2012', 'M Y'));?
// Wed Feb 01 2012 00:00:00 GMT-0800 (Pacific Standard Time)
I agree. But it would change behaviour which could be depended upon.
This bug affects date field component
If I'm trying to use the date field with "M Y" format, and I select "Feb 2012", as soon as I blur out of the field, it automatically changes it to "Mar 2012".
If somebody is relying on the current behavior, they're probably experiencing bugs they're not aware of a handful of days out of the year.
And besides, it causes a hard-to-find bug that can only be reproduced on certain days of the year with the Ext.form.field.Date component with a "M Y" setting.
Ext JS Premium Member
Wow, we just hit this bug and I cannot believe it isn't fixed yet. (Just tried it with 4.2.0)
Sorry, no further input so this is just to "vote" for this bug to be fixed.
Sencha Premium Member
This is how dates work in Oracle.
Originally Posted by yoh.suzuki
I understand and appreciate Animal's concern that changing this could negatively impact existing code. But the current behavior is fundamentally broken. I would be in favor of a new format string that implements the correct behavior (something like MON), or at the very least another flag on the function.
SELECT TO_CHAR(TO_DATE('02/2013', 'MM/YYYY'), 'MM/DD/YYYY') -- Shows '02/01/2013'
This one has been resolved. It was part of the 4.2.1 release, marked as EXTJSIV-9049.
To keep the behaviour change to a minimum, it will return a date closest to the current. For example if you set the date to May 31, and try to parse Jun, you will get Jun 30 as the date being returned.
Twitter - @evantrimboli