-
5 Jun 2012 2:48 PM #1
Ext.Date.parse "M Y" returns wrong date on certain dates
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:
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?Code: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
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/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
31 Dec 2012 2:43 PM #4
This bug affects date field component
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.
You found a bug! We've classified it as
EXTJSIV-6427
.
We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.


Reply With Quote