Date.parseDate bug

  • In Date.createParser, you call "new Date(y);" in the most nested if. The single argument Date constructor expects milliseconds not years.

    Here is a testcase:

    Date.parseDate("2007-0", "Y-m" ).toString();

    returns "Wed Dec 31 1969 16:00:02 GMT-0800 (Pacific Standard Time)"

    which is 2007 milliseconds after epoch.

    I would it expect to return

    "Thu May 24 2007 00:00:00 GMT-0700 (Pacific Daylight Time)"

    Michael


  • I believe adding a default month value will fix it:

    + "{return new Date(y, 0);}n"

    Thanks -- we'll get this updated.


  • Well, after looking into this a bit more, turns out that the parseDate function actually expects 1-based months, not 0-based JS-style months. You can of course argue which way is better, but that's the way it is. Based on that understanding, the current logic is valid as 0 should never be passed in as a month. To avoid this confusion, I have updated the parseDate docs in SVN accordingly.


    /**
    * Parses the passed string using the specified format. Note that this function expects dates in normal calendar
    * format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates. Any part of
    * the date format that is not specified will default to the current date value for that part. Time parts can also
    * be specified, but default to 0. Keep in mind that the input date string must precisely match the specified format
    * string or the parse operation will fail.
    * Example Usage:

    //dt = Fri May 25 2007 (current date)
    var dt = new Date();

    //dt = Thu May 25 2006 (today's month/day in 2006)
    dt = Date.parseDate("2006", "Y");

    //dt = Sun Jan 15 2006 (all date parts specified)
    dt = Date.parseDate("2006-1-15", "Y-m-d");

    //dt = Sun Jan 15 2006 15:20:01 GMT-0600 (CST)
    dt = Date.parseDate("2006-1-15 3:20:01 PM", "Y-m-d h:i: s A" );

    * @param {String} input The unparsed date as a string
    * @param {String} format The format the date is in
    * @return {Date} The parsed date
    * @static
    */







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Date.parseDate bug , Please add it free.