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.
  1. #1
    Sencha Premium Member
    Join Date
    Oct 2011
    Posts
    3
    Vote Rating
    2
    EJ.Beauchamp is on a distinguished road

      1  

    Exclamation 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)


  2. #2
    Ext Premium Member
    Join Date
    Sep 2009
    Posts
    48
    Vote Rating
    1
    yoh.suzuki is on a distinguished road

      1  

    Default


    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:

    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)
    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?

  3. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,458
    Vote Rating
    20
    Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough

      0  

    Default


    I agree. But it would change behaviour which could be depended upon.

  4. #4
    Sencha User
    Join Date
    Sep 2011
    Posts
    5
    Vote Rating
    0
    msumme is on a distinguished road

      0  

    Default 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.