5 Jun 2012 2:48 PM #1
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)
5 Jun 2012 5:53 PM #2
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:
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)
9 Jun 2012 9:14 AM #3
- Join Date
- Mar 2007
- Notts/Redwood City
- Vote Rating
I agree. But it would change behaviour which could be depended upon.Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
31 Dec 2012 2:43 PM #4
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.
31 May 2013 5:55 AM #5
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.
31 May 2013 7:42 AM #6
SELECT TO_CHAR(TO_DATE('02/2013', 'MM/YYYY'), 'MM/DD/YYYY') -- Shows '02/01/2013' FROM DUAL
2 Jun 2013 4:04 PM #7
- Join Date
- Apr 2007
- Sydney, Australia
- Vote Rating
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.Evan Trimboli
Twitter - @evantrimboli
Don't be afraid of the source code!