You found a bug! We've classified it as EXTJS-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,508
    Vote Rating
    56
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      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.

  5. #5
    Ext JS Premium Member mfranke's Avatar
    Join Date
    Mar 2010
    Posts
    20
    Vote Rating
    1
    mfranke is on a distinguished road

      0  

    Default


    BUMP!!!

    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.

  6. #6
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    72
    Vote Rating
    13
    eric.cook will become famous soon enough

      0  

    Default


    Quote Originally Posted by yoh.suzuki View Post
    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?
    This is how dates work in Oracle.

    Code:
    SELECT TO_CHAR(TO_DATE('02/2013', 'MM/YYYY'), 'MM/DD/YYYY') -- Shows '02/01/2013'
    FROM   DUAL
    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.

  7. #7
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,000
    Vote Rating
    649
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    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
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!