Changeset 11448

Show
Ignore:
Timestamp:
11/08/07 07:01:00 (14 months ago)
Author:
peller
Message:

Bryan's patch to fix DST problems. Refs #5047

Location:
dojo/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/date.js

    r11385 r11448  
    188188 
    189189        if(property){ 
    190                 sum["set"+property](sum["get"+property]()+amount); 
     190                sum["setUTC"+property](sum["getUTC"+property]()+amount); 
    191191        } 
    192192 
  • dojo/trunk/tests/date.js

    r8605 r11448  
    5454        // Create a fake Date object with toString and toLocaleString 
    5555        // results manually set to simulate tests for multiple browsers 
    56         function fakeDate(str, strLocale){ 
     56        function FakeDate(str, strLocale){ 
    5757                this.str = str || ''; 
    5858                this.strLocale = strLocale || ''; 
     
    6464                }; 
    6565        } 
    66         var dt = new fakeDate(); 
     66        var dt = new FakeDate(); 
    6767         
    6868        // FF 1.5 Ubuntu Linux (Breezy) 
     
    179179        t.is(dtB, dojo.date.add(dtA, interv, 1)); 
    180180 
    181         var interv = "day"; 
     181        interv = "day"; 
    182182        dtA = new Date(2000, 0, 1); 
    183183        dtB = new Date(2000, 0, 2); 
     
    283283        t.is(dtB, dojo.date.add(dtA, interv, 1)); 
    284284 
    285         dtA = new Date(2000, 11, 27, 12, 02); 
    286         dtB = new Date(2000, 11, 27, 13, 02); 
     285        dtA = new Date(2000, 11, 27, 12, 2); 
     286        dtB = new Date(2000, 11, 27, 13, 2); 
    287287        t.is(dtB, dojo.date.add(dtA, interv, 60)); 
    288288         
     
    483483        dtB = new Date(2001, 0, 1, 0, 0, 0, 0); 
    484484        t.is(1000, dojo.date.difference(dtA, dtB, interv)); 
     485}, 
     486function test_date_add_diff_year(t){ 
     487        var interv = ''; // Interval (e.g., year, month) 
     488        var dtA = null; // Date to increment 
     489        var dtB = null; // Expected result date 
     490         
     491        interv = "year"; 
     492        dtA = new Date(2005, 11, 27); 
     493        dtB = dojo.date.add(dtA, interv, 1); 
     494        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     495         
     496        dtA = new Date(2005, 11, 27); 
     497        dtB = dojo.date.add(dtA, interv, -1); 
     498        t.is(dojo.date.difference(dtA, dtB, interv), -1); 
     499         
     500        dtA = new Date(2000, 1, 29); 
     501        dtB = dojo.date.add(dtA, interv, 1); 
     502        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     503         
     504        dtA = new Date(2000, 1, 29); 
     505        dtB = dojo.date.add(dtA, interv, 5); 
     506        t.is(dojo.date.difference(dtA, dtB, interv), 5); 
     507         
     508        dtA = new Date(1900, 11, 31); 
     509        dtB = dojo.date.add(dtA, interv, 30); 
     510        t.is(dojo.date.difference(dtA, dtB, interv), 30); 
     511         
     512        dtA = new Date(1995, 11, 31); 
     513        dtB = dojo.date.add(dtA, interv, 35); 
     514        t.is(dojo.date.difference(dtA, dtB, interv), 35); 
     515}, 
     516function test_date_add_diff_quarter(t){ 
     517        var interv = ''; // Interval (e.g., year, month) 
     518        var dtA = null; // Date to increment 
     519        var dtB = null; // Expected result date 
     520        interv = "quarter"; 
     521        dtA = new Date(2000, 0, 1); 
     522        dtB = dojo.date.add(dtA, interv, 1); 
     523        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     524         
     525        dtA = new Date(2000, 1, 29); 
     526        dtB = dojo.date.add(dtA, interv, 2); 
     527        t.is(dojo.date.difference(dtA, dtB, interv), 2); 
     528         
     529        dtA = new Date(2000, 1, 29); 
     530        dtB = dojo.date.add(dtA, interv, 4); 
     531        t.is(dojo.date.difference(dtA, dtB, interv), 4); 
     532}, 
     533function test_date_add_diff_month(t){ 
     534        var interv = ''; // Interval (e.g., year, month) 
     535        var dtA = null; // Date to increment 
     536        var dtB = null; // Expected result date 
     537        interv = "month"; 
     538        dtA = new Date(2000, 0, 1); 
     539        dtB = dojo.date.add(dtA, interv, 1); 
     540        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     541         
     542        dtA = new Date(2000, 0, 31); 
     543        dtB = dojo.date.add(dtA, interv, 1); 
     544        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     545         
     546        dtA = new Date(2000, 1, 29); 
     547        dtB = dojo.date.add(dtA, interv, 12); 
     548        t.is(dojo.date.difference(dtA, dtB, interv), 12); 
     549}, 
     550function test_date_add_diff_week(t){ 
     551        var interv = ''; // Interval (e.g., year, month) 
     552        var dtA = null; // Date to increment 
     553        var dtB = null; // Expected result date 
     554        interv = "week"; 
     555        dtA = new Date(2000, 0, 1); 
     556        dtB = dojo.date.add(dtA, interv, 1); 
     557        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     558}, 
     559function test_date_add_diff_day(t){ 
     560        var interv = ''; // Interval (e.g., year, month) 
     561        var dtA = null; // Date to increment 
     562        var dtB = null; // Expected result date 
     563        interv = "day"; 
     564        dtA = new Date(2000, 0, 1); 
     565        dtB = dojo.date.add(dtA, interv, 1); 
     566        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     567         
     568        dtA = new Date(2001, 0, 1); 
     569        dtB = dojo.date.add(dtA, interv, 365); 
     570        t.is(dojo.date.difference(dtA, dtB, interv), 365); 
     571         
     572        dtA = new Date(2000, 0, 1); 
     573        dtB = dojo.date.add(dtA, interv, 366); 
     574        t.is(dojo.date.difference(dtA, dtB, interv), 366); 
     575         
     576        dtA = new Date(2000, 1, 28); 
     577        dtB = dojo.date.add(dtA, interv, 1); 
     578        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     579         
     580        dtA = new Date(2001, 1, 28); 
     581        dtB = dojo.date.add(dtA, interv, 1); 
     582        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     583         
     584        dtA = new Date(2000, 2, 1); 
     585        dtB = dojo.date.add(dtA, interv, -1); 
     586        t.is(dojo.date.difference(dtA, dtB, interv), -1); 
     587         
     588        dtA = new Date(2001, 2, 1); 
     589        dtB = dojo.date.add(dtA, interv, -1); 
     590        t.is(dojo.date.difference(dtA, dtB, interv), -1); 
     591         
     592        dtA = new Date(2000, 0, 1); 
     593        dtB = dojo.date.add(dtA, interv, -1); 
     594        t.is(dojo.date.difference(dtA, dtB, interv), -1); 
     595}, 
     596function test_date_add_diff_weekday(t){ 
     597        var interv = ''; // Interval (e.g., year, month) 
     598        var dtA = null; // Date to increment 
     599        var dtB = null; // Expected result date 
     600        interv = "weekday"; 
     601        // Sat, Jan 1 
     602        dtA = new Date(2000, 0, 1); 
     603        // Should be Mon, Jan 3 
     604        dtB = dojo.date.add(dtA, interv, 1); 
     605        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     606         
     607        // Sun, Jan 2 
     608        dtA = new Date(2000, 0, 2); 
     609        // Should be Mon, Jan 3 
     610        dtB = dojo.date.add(dtA, interv, 1); 
     611        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     612         
     613        // Sun, Jan 2 
     614        dtA = new Date(2000, 0, 2); 
     615        // Should be Fri, Jan 7 
     616        dtB = dojo.date.add(dtA, interv, 5); 
     617        t.is(dojo.date.difference(dtA, dtB, interv), 5); 
     618         
     619        // Sun, Jan 2 
     620        dtA = new Date(2000, 0, 2); 
     621        // Should be Mon, Jan 10 
     622        dtB = dojo.date.add(dtA, interv, 6); 
     623        t.is(dojo.date.difference(dtA, dtB, interv), 6); 
     624         
     625        // Mon, Jan 3 
     626        dtA = new Date(2000, 0, 3); 
     627        // Should be Mon, Jan 17 
     628        dtB = dojo.date.add(dtA, interv, 10); 
     629        t.is(dojo.date.difference(dtA, dtB, interv), 10); 
     630         
     631        // Sat, Jan 8 
     632        dtA = new Date(2000, 0, 8); 
     633        // Should be Mon, Jan 3 
     634        dtB = dojo.date.add(dtA, interv, -5); 
     635        t.is(dojo.date.difference(dtA, dtB, interv), -5); 
     636         
     637        // Sun, Jan 9 
     638        dtA = new Date(2000, 0, 9); 
     639        // Should be Wed, Jan 5 
     640        dtB = dojo.date.add(dtA, interv, -3); 
     641        t.is(dojo.date.difference(dtA, dtB, interv), -3); 
     642         
     643        // Sun, Jan 23 
     644        dtA = new Date(2000, 0, 23); 
     645        // Should be Fri, Jan 7 
     646        dtB = dojo.date.add(dtA, interv, -11); 
     647        t.is(dojo.date.difference(dtA, dtB, interv), -11); 
     648}, 
     649function test_date_add_diff_hour(t){ 
     650        var interv = ''; // Interval (e.g., year, month) 
     651        var dtA = null; // Date to increment 
     652        var dtB = null; // Expected result date 
     653        interv = "hour"; 
     654        dtA = new Date(2000, 0, 1, 11); 
     655        dtB = dojo.date.add(dtA, interv, 1); 
     656        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     657 
     658        dtA = new Date(2001, 9, 28, 0); 
     659        dtB = dojo.date.add(dtA, interv, 1); 
     660        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     661 
     662        dtA = new Date(2001, 9, 28, 23); 
     663        dtB = dojo.date.add(dtA, interv, 1); 
     664        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     665 
     666        dtA = new Date(2001, 11, 31, 23); 
     667        dtB = dojo.date.add(dtA, interv, 1); 
     668        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     669}, 
     670function test_date_add_diff_minute(t){ 
     671        var interv = ''; // Interval (e.g., year, month) 
     672        var dtA = null; // Date to increment 
     673        var dtB = null; // Expected result date 
     674        interv = "minute"; 
     675        dtA = new Date(2000, 11, 31, 23, 59); 
     676        dtB = dojo.date.add(dtA, interv, 1); 
     677        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     678 
     679        dtA = new Date(2000, 11, 27, 12, 2); 
     680        dtB = dojo.date.add(dtA, interv, 60); 
     681        t.is(dojo.date.difference(dtA, dtB, interv), 60); 
     682}, 
     683function test_date_add_diff_second(t){ 
     684        var interv = ''; // Interval (e.g., year, month) 
     685        var dtA = null; // Date to increment 
     686        var dtB = null; // Expected result date 
     687        console.debug("second"); 
     688        interv = "second"; 
     689        dtA = new Date(2000, 11, 31, 23, 59, 59); 
     690        dtB = dojo.date.add(dtA, interv, 1); 
     691        t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     692 
     693        dtA = new Date(2000, 11, 27, 8, 10, 59); 
     694        dtB = dojo.date.add(dtA, interv, 60); 
     695        t.is(dojo.date.difference(dtA, dtB, interv), 60); 
     696         
     697        // Test environment JS Date doesn't support millisec? 
     698        //interv = "millisecond"; 
     699        // 
     700        //dtA = new Date(2000, 11, 31, 23, 59, 59, 999); 
     701        //dtB = dojo.date.add(dtA, interv, 1); 
     702        //t.is(dojo.date.difference(dtA, dtB, interv), 1); 
     703        // 
     704        //dtA = new Date(2000, 11, 27, 8, 10, 53, 2); 
     705        //dtB = dojo.date.add(dtA, interv, 1000); 
     706        //t.is(dojo.date.difference(dtA, dtB, interv), 1000); 
    485707} 
    486708        ]