Ticket #5911: patch5911.diff

File patch5911.diff, 3.2 kB (added by wolfram, 11 months ago)
  • dojo/date/stamp.js

     
    2525        //              input may return null.  Arguments which are out of bounds will be handled 
    2626        //              by the Date constructor (e.g. January 32nd typically gets resolved to February 1st) 
    2727        // 
    28         //      formattedString: 
     28        //      formattedString: 
    2929        //              A string such as 2005-06-30T08:05:00-07:00 or 2005-06-30 or T08:05:00 
     30        //               
     31        //              >>> var t = dojo.date.stamp.fromISOString("2008-01-20T21:45:03") // Note the "T" before the time! 
     32        //              >>> String(t).match(/Sun Jan 20 2008 21:45:03/) // Do only test for the beginning of the string, the end contains the timezone and that might differ on each test system 
     33        //              ["Sun Jan 20 2008 21:45:03"] 
    3034        // 
     35        //              >>> dojo.date.stamp.fromISOString("2008-01-20 21:45:03") // Note the space before the time! 
     36        //              >>> String(t).match(/Sun Jan 20 2008 21:45:03/) 
     37        //              ["Sun Jan 20 2008 21:45:03"] 
     38        // 
    3139        //      defaultTime: 
    3240        //              Used for defaults for fields omitted in the formattedString. 
    3341        //              Uses 1970-01-01T00:00:00.0Z by default. 
     
    3543        if(!dojo.date.stamp._isoRegExp){ 
    3644                dojo.date.stamp._isoRegExp = 
    3745//TODO: could be more restrictive and check for 00-59, etc. 
    38                         /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/; 
     46                        /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:[ T](\d{2}):(\d{2})(?::(\d{2})(.\d+)?)?((?:[+-](\d{2}):(\d{2}))|Z)?)?$/; 
    3947        } 
    4048 
    4149        var match = dojo.date.stamp._isoRegExp.exec(formattedString); 
     
    100108        var getter = options.zulu ? "getUTC" : "get"; 
    101109        var date = ""; 
    102110        if(options.selector != "time"){ 
    103                 date = [dateObject[getter+"FullYear"](), _(dateObject[getter+"Month"]()+1), _(dateObject[getter+"Date"]())].join('-'); 
     111                var year = dateObject[getter+"FullYear"](); 
     112                // For a year 100>999 getFullYear() returns a three digit number! 
     113                year = year<1000 ? "0"+year : year; 
     114                date = [year, _(dateObject[getter+"Month"]()+1), _(dateObject[getter+"Date"]())].join('-'); 
    104115        } 
    105116        formattedDate.push(date); 
    106117        if(options.selector != "date"){ 
  • dojo/tests/date/stamp.js

     
    1414        t.is(5,date.getMinutes()); 
    1515        t.is(0,date.getSeconds()); 
    1616 
     17        var rfc  = "2005-06-29 08:05:00"; 
     18        var date = dojo.date.stamp.fromISOString(rfc); 
     19        t.is(2005,date.getFullYear()); 
     20        t.is(5,date.getMonth()); 
     21        t.is(29,date.getDate()); 
     22        t.is(8,date.getHours()); 
     23        t.is(5,date.getMinutes()); 
     24        t.is(0,date.getSeconds()); 
     25 
    1726        rfc  = "2004-02-29"; 
    1827        date = dojo.date.stamp.fromISOString(rfc); 
    1928        t.is(2004,date.getFullYear()); 
     
    4554        //truncate for comparison 
    4655        t.is("0101-01",rfc.substring(0,7)); 
    4756 
     57        // Make sure years between 100 and 999 are represented by four digits 
     58        // see http://trac.dojotoolkit.org/ticket/5911 
     59        date = new Date(100,1,2); 
     60        rfc = dojo.date.stamp.toISOString(date); 
     61        t.is("0100-",rfc.substring(0,5)); 
     62        date = new Date(999,1,2); 
     63        rfc = dojo.date.stamp.toISOString(date); 
     64        t.is("0999-",rfc.substring(0,5)); 
     65 
    4866        rfc  = "0101-01-01"; 
    4967        date = dojo.date.stamp.fromISOString(rfc); 
    5068        t.is(101,date.getFullYear());