Changeset 1351

Show
Ignore:
Timestamp:
03/31/08 09:37:01 (3 months ago)
Author:
jay
Message:

added support and testing for pre-1900 dates

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mochikit/trunk/MochiKit/DateTime.js

    r1319 r1351  
    3030        return null; 
    3131    } 
    32     return new Date(iso[0], iso[1] - 1, iso[2]); 
     32        var date = new Date(); 
     33        date.setFullYear(iso[0]); 
     34        date.setMonth(iso[1] - 1); 
     35        date.setDate(iso[2]); 
     36    return date; 
    3337}; 
    3438 
     
    116120    } 
    117121    var _padTwo = MochiKit.DateTime._padTwo; 
     122        var _padFour = MochiKit.DateTime._padFour; 
    118123    return [ 
    119         date.getFullYear(), 
     124        _padFour(date.getFullYear()), 
    120125        _padTwo(date.getMonth() + 1), 
    121126        _padTwo(date.getDate()) 
     
    135140MochiKit.DateTime._padTwo = function (n) { 
    136141    return (n > 9) ? n : "0" + n; 
     142}; 
     143 
     144MochiKit.DateTime._padFour = function(n) { 
     145        switch(n.toString().length) { 
     146                case 1: return "000" + n; break; 
     147                case 2: return "00" + n; break; 
     148                case 3: return "0" + n; break; 
     149                case 4: 
     150                default: 
     151                        return n; 
     152        } 
    137153}; 
    138154 
  • mochikit/trunk/tests/test_DateTime.js

    r653 r1351  
    1717    t.ok(objEqual(testDate, new Date("June 8, 2005")), "matches string date"); 
    1818    t.is(toISODate(testDate), '2005-06-08', 'toISODate ok'); 
     19 
     20        var testDate = isoDate('0500-12-12'); 
     21        t.is(testDate.getFullYear(), 500, 'isoDate year ok for year < 1000'); 
     22        t.is(testDate.getDate(), 12, 'isoDate day ok for year < 1000'); 
     23        t.is(testDate.getMonth(), 11, 'isoDate month ok for year < 1000'); 
     24        t.ok(objEqual(testDate, new Date("December 12, 0500")), "matches string date for year < 1000"); 
     25        t.is(toISODate(testDate), '0500-12-12', 'toISODate ok for year < 1000'); 
    1926 
    2027    t.is(compare(new Date("February 3, 2005"), new Date(2005, 1, 3)), 0, "dates compare eq");