Home | History | Annotate | Download | only in Date
      1 /* The contents of this file are subject to the Netscape Public
      2  * License Version 1.1 (the "License"); you may not use this file
      3  * except in compliance with the License. You may obtain a copy of
      4  * the License at http://www.mozilla.org/NPL/
      5  *
      6  * Software distributed under the License is distributed on an "AS
      7  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
      8  * implied. See the License for the specific language governing
      9  * rights and limitations under the License.
     10  *
     11  * The Original Code is Mozilla Communicator client code, released March
     12  * 31, 1998.
     13  *
     14  * The Initial Developer of the Original Code is Netscape Communications
     15  * Corporation. Portions created by Netscape are
     16  * Copyright (C) 1998 Netscape Communications Corporation. All
     17  * Rights Reserved.
     18  *
     19  * Contributor(s):
     20  *
     21  */
     22 /**
     23     File Name:          15.9.5.36-1.js
     24     ECMA Section:       15.9.5.36 Date.prototype.setFullYear(year [, mon [, date ]] )
     25     Description:
     26 
     27     If mon is not specified, this behaves as if mon were specified with the
     28     value getMonth( ). If date is not specified, this behaves as if date were
     29     specified with the value getDate( ).
     30 
     31    1.   Let t be the result of LocalTime(this time value); but if this time
     32         value is NaN, let t be +0.
     33    2.   Call ToNumber(year).
     34    3.   If mon is not specified, compute MonthFromTime(t); otherwise, call
     35         ToNumber(mon).
     36    4.   If date is not specified, compute DateFromTime(t); otherwise, call
     37         ToNumber(date).
     38    5.   Compute MakeDay(Result(2), Result(3), Result(4)).
     39    6.   Compute UTC(MakeDate(Result(5), TimeWithinDay(t))).
     40    7.   Set the [[Value]] property of the this value to TimeClip(Result(6)).
     41    8.   Return the value of the [[Value]] property of the this value.
     42 
     43     Author:             christine (at) netscape.com
     44     Date:               12 november 1997
     45 
     46     Added test cases for Year 2000 Compatilibity Testing.
     47 
     48 */
     49     var SECTION = "15.9.5.36-1";
     50     var VERSION = "ECMA_1";
     51     startTest();
     52 
     53     writeHeaderToLog( SECTION + " Date.prototype.setFullYear(year [, mon [, date ]] )");
     54 
     55     getTestCases();
     56     test();
     57 
     58 function test() {
     59     for ( tc=0; tc < testcases.length; tc++ ) {
     60         testcases[tc].passed = writeTestCaseResult(
     61                             testcases[tc].expect,
     62                             testcases[tc].actual,
     63                             testcases[tc].description +" = "+
     64                             testcases[tc].actual );
     65 
     66         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     67     }
     68     stopTest();
     69     return ( testcases );
     70 }
     71 function getTestCases() {
     72     // Jan 1, 2005
     73     addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005);TDATE",
     74                     UTCDateFromTime(SetFullYear(0,2005)),
     75                     LocalDateFromTime(SetFullYear(0,2005)) );
     76 
     77     addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005,0);TDATE",
     78                     UTCDateFromTime(SetFullYear(0,2005,0)),
     79                     LocalDateFromTime(SetFullYear(0,2005,0)) );
     80 
     81     addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005,0,1);TDATE",
     82                     UTCDateFromTime(SetFullYear(0,2005,0,1)),
     83                     LocalDateFromTime(SetFullYear(0,2005,0,1)) );
     84 
     85 }
     86 function addNewTestCase( DateString, UTCDate, LocalDate) {
     87     DateCase = eval( DateString );
     88 
     89     var item = testcases.length;
     90 
     91 //    fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
     92 
     93     testcases[item++] = new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
     94     testcases[item++] = new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
     95 
     96     testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
     97     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
     98     testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
     99     testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
    100     testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
    101     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
    102     testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
    103     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
    104 
    105     testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
    106     testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
    107     testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
    108     testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
    109     testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
    110     testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
    111     testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
    112     testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
    113 
    114     DateCase.toString = Object.prototype.toString;
    115 
    116     testcases[item++] = new TestCase( SECTION,
    117                                       DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
    118                                       "[object Date]",
    119                                       DateCase.toString() );
    120 }
    121 
    122 function MyDate() {
    123     this.year = 0;
    124     this.month = 0;
    125     this.date = 0;
    126     this.hours = 0;
    127     this.minutes = 0;
    128     this.seconds = 0;
    129     this.ms = 0;
    130 }
    131 function LocalDateFromTime(t) {
    132     t = LocalTime(t);
    133     return ( MyDateFromTime(t) );
    134 }
    135 function UTCDateFromTime(t) {
    136  return ( MyDateFromTime(t) );
    137 }
    138 function MyDateFromTime( t ) {
    139     var d = new MyDate();
    140     d.year = YearFromTime(t);
    141     d.month = MonthFromTime(t);
    142     d.date = DateFromTime(t);
    143     d.hours = HourFromTime(t);
    144     d.minutes = MinFromTime(t);
    145     d.seconds = SecFromTime(t);
    146     d.ms = msFromTime(t);
    147 
    148     d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
    149     d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
    150     d.day = WeekDay( d.value );
    151 
    152     return (d);
    153 }
    154 function SetFullYear( t, year, mon, date ) {
    155     var T = ( isNaN(t) ) ? 0 : LocalTime(t) ;
    156     var YEAR = Number( year );
    157     var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon );
    158     var DATE = ( date == void 0 ) ? DateFromTime(T)  : Number( date );
    159 
    160     var DAY = MakeDay( YEAR, MONTH, DATE );
    161     var UTC_DATE = UTC(MakeDate( DAY, TimeWithinDay(T)));
    162 
    163     return ( TimeClip(UTC_DATE) );
    164 }