This project is archived and is in readonly mode.

#132 ✓resolved
Waldo Malqui Silva

Date.parse ignore February

Reported by Waldo Malqui Silva | September 29th, 2009 @ 11:54 PM | in 1.2.5.1

When I try to parse a date in February the output is in March

Date.parse('2009-01-01')
Thu Jan 01 2009 00:00:00 GMT-0500

Date.parse('2009-02-01')
Sun Mar 01 2009 00:00:00 GMT-0500

Date.parse('2009-03-01')
Sun Mar 01 2009 00:00:00 GMT-0500

Date.parse('2009-04-01')
Wed Apr 01 2009 00:00:00 GMT-0500

Date.parse('2009-03-00')
Sat Feb 28 2009 00:00:00 GMT-0500

Date.parse('2009-02-31')
Tue Mar 31 2009 00:00:00 GMT-0500

Date.parse('2009-02-30')
Mon Mar 30 2009 00:00:00 GMT-0500

Date.parse('2009-02-29')
Sun Mar 29 2009 00:00:00 GMT-0500

Date.parse('2009-02-28')
Sat Mar 28 2009 00:00:00 GMT-0500

Comments and changes to this ticket

  • Scott Kyle

    Scott Kyle October 2nd, 2009 @ 01:12 AM

    • Milestone set to 1.2.4.1
    • State changed from “new” to “open”
    • Assigned user set to “Scott Kyle”

    February is a dirty non-conformist month, so we removed it. :-)

    I kid, this is a major problem and I'll address it ASAP.

  • Scott Kyle

    Scott Kyle October 2nd, 2009 @ 04:02 PM

    Hi, I couldn't reproduce this bug. Please let me know what browser/version/platform you were on when encountering this problem. Thanks.

  • Waldo Malqui Silva

    Waldo Malqui Silva October 2nd, 2009 @ 04:22 PM

    OS : Windows 7 Ultimate (32bits)
    browser : Firefox 3.5.3 / Chrome 3.0.195.4 / Internet Explorer 8.0.7600.16385

  • Waldo Malqui Silva

    Waldo Malqui Silva October 2nd, 2009 @ 04:35 PM

    Hi when I try again can't repeat the bug then I change the date to 29th September and the bug show again

    Test :

    28th September : OK
    29th September : Bug
    30th September : Bug
    01st October : OK
    02nd October : OK
    ... 28th October : OK
    29th October : Bug

    Very strange

  • Scott Kyle

    Scott Kyle October 2nd, 2009 @ 04:45 PM

    I'm still having trouble reproducing, please put something into http://mooshell.net that triggers this bug and share the URL. Thanks.

  • Sebastian Markbåge

    Sebastian Markbåge October 2nd, 2009 @ 05:25 PM

    • State changed from “open” to “invalid”

    I couldn't reproduce this bug in any of the mentioned browsers.

    Please note that '2009-02-29' is interpreted as March 1st. This is expected behavior since 2009 isn't a leap year. However, 2008 is, so '2008-02-29' is interpreted as February 29th.

    Make sure you have the latest versions of MooTools and that you don't have any other conflicting frameworks causing the bug.

    Or as Scott mentioned, put an example up on MooShell demonstrating the problem.

  • Waldo Malqui Silva

    Waldo Malqui Silva October 2nd, 2009 @ 06:19 PM

    Mootools:

    Mootools (core) : 1.2.3
    Mootools (more) : 1.2.3.1

    How to reproduce:

    This error occurs when the "system date" is between the 29th and 31st of the current month to reproduce just set the "system date" between these days and try "Date.parse" with any date of February

    Firebug Output:
    new Date()
    Fri Oct 30 2009 11:58:45 GMT-0500

    Date.parse( "2009-02-01" )
    Sun Mar 01 2009 00:00:00 GMT-0500

    Date.parse( "2009-02-10" )
    Tue Mar 10 2009 00:00:00 GMT-0500

    Date.parse( "2009-02-20" )
    Fri Mar 20 2009 00:00:00 GMT-0500

    Date.parse( "2009-02-28" )
    Sat Mar 28 2009 00:00:00 GMT-0500

    Date.parse( "2009-02-29" )
    Sun Mar 29 2009 00:00:00 GMT-0500

    Date.parse( "2009-02-30" )
    Mon Mar 30 2009 00:00:00 GMT-0500

    Date.parse( "2009-03-01" )
    Sun Mar 01 2009 00:00:00 GMT-0500

    Operating System:
    wimdows 7 Ultimate (32bits)
    windows XP SP3 (32bits)
    Mac OSX Leopard

    Browser:
    Firefox 3.5.3
    Chrome 3.0.195.4
    Internet Explorer 8.0.7600.16385
    Safari
    Camino

    Screenshot :
    http://archivos.traveltips.com.pe/mootools-bug.gif

    Extra:
    Sorry for my badly english but my primary language is spanish.

  • Waldo Malqui Silva
  • Sebastian Markbåge

    Sebastian Markbåge October 2nd, 2009 @ 07:50 PM

    • State changed from “invalid” to “open”

    Oh I see.

    The problem is that the date defaults to the current date. Then the various parts are set individually in a problematic order.

    Let's say the current date is 2009-09-30 and we want to set this to 2009-02-10.

    • The year is set to 2009.

    • Then the month is set to 2. Which means it is set to 2009-02-30. That automatically turns into 2009-03-01.

    • Then the day is set to 10. Which ends up being 2009-03-10.

    Setting the date in the reverse order doesn't work either. Let's say the current date is 2009-04-30 and we want to set it to 2009-03-31. If we set the day first, we get the same issue.

    It would probably be better to reset the date to january 1st before parsing. Just like time is reset to 00:00:00.

    Thanks argosback!

  • Scott Kyle

    Scott Kyle October 2nd, 2009 @ 08:18 PM

    I resolved this issue and will push the fix to GitHub once my computer has net access tomorrow. The solution isn't as easy as defaulting the date to Jan 1st because that would break some parsers.

  • Scott Kyle

    Scott Kyle October 3rd, 2009 @ 11:38 PM

    • State changed from “open” to “resolved”

    Okay, I pushed this to my fork, will go in trunk soon.

  • Waldo Malqui Silva

    Waldo Malqui Silva October 7th, 2009 @ 06:02 PM

    Hi Scott, I try your patch and I get This

    Date.parse('2009-02-01')
    ["2009-02-01", "2009", "02", "01", ...]
    [null, "Y", "m", "d", "H", "M", "S", "s", "p", "T"]
    Tue Jan 01 0002 00:00:00 GMT-0500
    
    Date.parse('2009-02-02')
    ["2009-02-02", "2009", "02", "02", ...]
    [null, "Y", "m", "d", "H", "M", "S", "s", "p", "T"]
    Fri Feb 01 0002 00:00:00 GMT-0500 $family=Object
    
    Date.parse('2009-03-02')
    ["2009-03-02", "2009", "03", "02", ...]
    [null, "Y", "m", "d", "H", "M", "S", "s", "p", "T"]
    Sat Feb 01 0003 00:00:00 GMT-0500 $family=Object
    
    Date.parse('2009-04-02')
    ["2009-04-02", "2009", "04", "02", ...]
    [null, "Y", "m", "d", "H", "M", "S", "s", "p", "T"]
    Sun Feb 01 0004 00:00:00 GMT-0500 $family=Object
    

    I make this little change

    Source/Native/Date.js
    392 bits = bits.slice(1).associate(parsed**.slice(1)**);
    

    And get this for me particular date format to parse (yyyy-mm-dd)

    Date.parse('2009-02-01')
    ["2009", "02", "01", ...]
    ["Y", "m", "d", "H", "M", "S", "s", "p", "T"]
    Sun Feb 01 2009 00:00:00 GMT-0500
    
    Date.parse('2009-02-02')
    ["2009", "02", "02", ...]
    ["Y", "m", "d", "H", "M", "S", "s", "p", "T"]
    Mon Feb 02 2009 00:00:00 GMT-0500
    
    Date.parse('2009-02-28')
    ["2009", "02", "28", ...]
    ["Y", "m", "d", "H", "M", "S", "s", "p", "T"]
    Sat Feb 28 2009 00:00:00 GMT-0500
    
    Date.parse('2009-04-01')
    ["2009", "04", "01", ...]
    ["Y", "m", "d", "H", "M", "S", "s", "p", "T"]
    Wed Apr 01 2009 00:00:00 GMT-0500
    
    Date.parse('2009-05-01')
    ["2009", "05", "01", ...]
    ["Y", "m", "d", "H", "M", "S", "s", "p", "T"]
    Fri May 01 2009 00:00:00 GMT-0500
    
  • Scott Kyle

    Scott Kyle October 8th, 2009 @ 06:22 PM

    Something went wrong in that commit where I changed var parsed = [null] to var parsed = [], but it doesn't show up in the diff. I can't find where it finally committed, but HEAD has it, so try the latest rather than that particular commit.

  • tvr

    tvr January 20th, 2010 @ 10:43 PM

    • Tag changed from 1.2.3.1, bug to 1.2.3.1, 1.2.4.2, bug, date

    I'm not so sure that this has been completely resolved. See accompanying shell.
    http://mootools.net/shell/APWfn/

  • tvr

    tvr January 20th, 2010 @ 10:49 PM

    Ug... The last shell version I noted has a lot of copy/paste errors. Here is the corrected version.
    http://mootools.net/shell/APWfn/2/

  • Scott Kyle

    Scott Kyle January 20th, 2010 @ 11:02 PM

    • Milestone changed from 1.2.4.1 to 1.2.4.3
    • State changed from “resolved” to “open”

    Thanks a lot for this shell, this is a slightly different bug, but one that I will try to fix today.

  • Aaron Newton

    Aaron Newton January 28th, 2010 @ 07:52 AM

    is this fixed? Scott, I've pulled your latest and greatest...

  • redshirt

    redshirt February 1st, 2010 @ 03:49 AM

    I believe date conversions are broken. When I call Date.parse on 2010-02-16, I get 2010-03-16 back.
    For more context, I originally discovered this when flipping through my implementation of the MooTools Events Calendar (http://dansnetwork.com/mootools/events-calendar/). For all 2010 months, every even month's events were being shown in the following month: February's events were showing up in March, April's events were showing up in May, etc. (March events were still showing up in March, though). When I click back to 2009, events odd-numbered months move to the following even-numbered month (sept-->oct).

    The calendar does something like this:

    var eEnd = Date.parse(this.options.cEvents[i].end)

    Since both Feb and March dates are being returned as March dates, February is blank and March is full of different events.

  • redshirt

    redshirt February 1st, 2010 @ 05:02 AM

    The Date.parse() now returns the expected result (this happened at the stroke of midnight)

  • Aaron Newton

    Aaron Newton February 9th, 2010 @ 05:12 AM

    • Milestone changed from 1.2.4.3 to 1.2.5.2
  • Varyen

    Varyen February 11th, 2010 @ 02:10 PM

    Problem in date build() function.

    When you're parsing bits you should set year as soon as possible. With this fix http://mootools.net/shell/APWfn/2/ works as expected.

    return {
        format: format,
        re: new RegExp('^' + re + '$', 'i'),
        handler: function(bits){
            bits = bits.slice(1).associate(parsed);
            var date = new Date().clearTime();
    
            // first of all set year to final value
            if ('y' in bits) handle.call(date, 'y', bits['y']);
            if ('Y' in bits) handle.call(date, 'Y', bits['Y']);
    
            if ('d' in bits) handle.call(date, 'd', 1);
            if ('m' in bits || 'b' in bits || 'B' in bits) handle.call(date, 'm', 1);
            for (var key in bits) handle.call(date, key, bits[key]);
            return date;
        }
    };
    
  • backyard

    backyard March 31st, 2010 @ 09:27 PM

    I'm having trouble with the Events Calendar, every event I have for February (pretty much all of the even months) goes to March (or the next odd-number month). Can anybody tell me how I can correct this problem.

  • ronin-76573 (at lighthouseapp)

    ronin-76573 (at lighthouseapp) July 26th, 2010 @ 10:07 AM

    • Milestone order changed from “0” to “0”

    i don't know if you fixed it yet, but i have mootools core: 1.2.4 mootools more 1.2.4.4 and i still get problems when parsing february.

    the problem is that it doesn't check for leapyears. reproducing code:

    var d = new Date();
    d.parse("2012/2/1");
    alert("date: "+d.format('%Y/%B/%d')+"\nlast day of month: "+d.get('lastdayofmonth'));

    in this code i expect 28, but get 29. that must also be your problem in http://mootools.net/shell/APWfn/2/

  • Scott Kyle

    Scott Kyle September 5th, 2010 @ 08:12 AM

    • State changed from “open” to “resolved”
  • Aaron Newton

    Aaron Newton October 12th, 2010 @ 04:09 AM

    • Milestone changed from 1.2.5.2 to 1.2.5.1
    • Milestone order changed from “2” to “0”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The MooTools Extensions

Pages