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.37-1.js 24 ECMA Section: 15.9.5.37 Date.prototype.setUTCFullYear(year [, mon [, date ]] ) 25 Description: 26 27 If mon is not specified, this behaves as if mon were specified with the 28 value getUTCMonth( ). If date is not specified, this behaves as if date 29 were specified with the value getUTCDate( ). 30 31 1. Let t be this time value; but if this time value is NaN, let t be +0. 32 2. Call ToNumber(year). 33 3. If mon is not specified, compute MonthFromTime(t); otherwise, call 34 ToNumber(mon). 35 4. If date is not specified, compute DateFromTime(t); otherwise, call 36 ToNumber(date). 37 5. Compute MakeDay(Result(2), Result(3), Result(4)). 38 6. Compute MakeDate(Result(5), TimeWithinDay(t)). 39 7. Set the [[Value]] property of the this value to TimeClip(Result(6)). 40 8. Return the value of the [[Value]] property of the this value. 41 42 Author: christine (at) netscape.com 43 Date: 12 november 1997 44 45 Added some Year 2000 test cases. 46 */ 47 var SECTION = "15.9.5.37-1"; 48 var VERSION = "ECMA_1"; 49 startTest(); 50 51 writeHeaderToLog( SECTION + " Date.prototype.setUTCFullYear(year [, mon [, date ]] )"); 52 53 getTestCases(); 54 test(); 55 56 function test() { 57 for ( tc=0; tc < testcases.length; tc++ ) { 58 testcases[tc].passed = writeTestCaseResult( 59 testcases[tc].expect, 60 testcases[tc].actual, 61 testcases[tc].description +" = "+ 62 testcases[tc].actual ); 63 64 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 65 } 66 stopTest(); 67 return ( testcases ); 68 } 69 70 function getTestCases() { 71 72 // Dates around 1970 73 74 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1970);TDATE", 75 UTCDateFromTime(SetUTCFullYear(0,1970)), 76 LocalDateFromTime(SetUTCFullYear(0,1970)) ); 77 78 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1971);TDATE", 79 UTCDateFromTime(SetUTCFullYear(0,1971)), 80 LocalDateFromTime(SetUTCFullYear(0,1971)) ); 81 82 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1972);TDATE", 83 UTCDateFromTime(SetUTCFullYear(0,1972)), 84 LocalDateFromTime(SetUTCFullYear(0,1972)) ); 85 86 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1968);TDATE", 87 UTCDateFromTime(SetUTCFullYear(0,1968)), 88 LocalDateFromTime(SetUTCFullYear(0,1968)) ); 89 90 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1969);TDATE", 91 UTCDateFromTime(SetUTCFullYear(0,1969)), 92 LocalDateFromTime(SetUTCFullYear(0,1969)) ); 93 94 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1969);TDATE", 95 UTCDateFromTime(SetUTCFullYear(0,1969)), 96 LocalDateFromTime(SetUTCFullYear(0,1969)) ); 97 /* 98 // Dates around 2000 99 100 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2000);TDATE", 101 UTCDateFromTime(SetUTCFullYear(0,2000)), 102 LocalDateFromTime(SetUTCFullYear(0,2000)) ); 103 104 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2001);TDATE", 105 UTCDateFromTime(SetUTCFullYear(0,2001)), 106 LocalDateFromTime(SetUTCFullYear(0,2001)) ); 107 108 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1999);TDATE", 109 UTCDateFromTime(SetUTCFullYear(0,1999)), 110 LocalDateFromTime(SetUTCFullYear(0,1999)) ); 111 112 // Dates around 29 February 2000 113 114 var UTC_FEB_29_1972 = TIME_1970 + TimeInYear(1970) + TimeInYear(1971) + 115 31*msPerDay + 28*msPerDay; 116 117 var PST_FEB_29_1972 = UTC_FEB_29_1972 - TZ_DIFF * msPerHour; 118 119 addNewTestCase( "TDATE = new Date("+UTC_FEB_29_1972+"); "+ 120 "TDATE.setUTCFullYear(2000);TDATE", 121 UTCDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)), 122 LocalDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)) ); 123 124 addNewTestCase( "TDATE = new Date("+PST_FEB_29_1972+"); "+ 125 "TDATE.setUTCFullYear(2000);TDATE", 126 UTCDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)), 127 LocalDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)) ); 128 129 // Dates around 2005 130 131 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2005);TDATE", 132 UTCDateFromTime(SetUTCFullYear(0,2005)), 133 LocalDateFromTime(SetUTCFullYear(0,2005)) ); 134 135 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2004);TDATE", 136 UTCDateFromTime(SetUTCFullYear(0,2004)), 137 LocalDateFromTime(SetUTCFullYear(0,2004)) ); 138 139 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2006);TDATE", 140 UTCDateFromTime(SetUTCFullYear(0,2006)), 141 LocalDateFromTime(SetUTCFullYear(0,2006)) ); 142 143 144 // Dates around 1900 145 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1900);TDATE", 146 UTCDateFromTime(SetUTCFullYear(0,1900)), 147 LocalDateFromTime(SetUTCFullYear(0,1900)) ); 148 149 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1899);TDATE", 150 UTCDateFromTime(SetUTCFullYear(0,1899)), 151 LocalDateFromTime(SetUTCFullYear(0,1899)) ); 152 153 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1901);TDATE", 154 UTCDateFromTime(SetUTCFullYear(0,1901)), 155 LocalDateFromTime(SetUTCFullYear(0,1901)) ); 156 157 */ 158 } 159 function addNewTestCase( DateString, UTCDate, LocalDate) { 160 DateCase = eval( DateString ); 161 162 var item = testcases.length; 163 164 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year; 165 166 testcases[item++] = new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); 167 testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); 168 169 testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); 170 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); 171 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); 172 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() ); 173 testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); 174 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); 175 testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); 176 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); 177 178 testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); 179 testcases[item++] = new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); 180 testcases[item++] = new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); 181 testcases[item++] = new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() ); 182 testcases[item++] = new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); 183 testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); 184 testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); 185 testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); 186 187 DateCase.toString = Object.prototype.toString; 188 189 testcases[item++] = new TestCase( SECTION, 190 DateString+".toString=Object.prototype.toString;"+DateString+".toString()", 191 "[object Date]", 192 DateCase.toString() ); 193 } 194 195 function MyDate() { 196 this.year = 0; 197 this.month = 0; 198 this.date = 0; 199 this.hours = 0; 200 this.minutes = 0; 201 this.seconds = 0; 202 this.ms = 0; 203 } 204 function LocalDateFromTime(t) { 205 t = LocalTime(t); 206 return ( MyDateFromTime(t) ); 207 } 208 function UTCDateFromTime(t) { 209 return ( MyDateFromTime(t) ); 210 } 211 function MyDateFromTime( t ) { 212 var d = new MyDate(); 213 d.year = YearFromTime(t); 214 d.month = MonthFromTime(t); 215 d.date = DateFromTime(t); 216 d.hours = HourFromTime(t); 217 d.minutes = MinFromTime(t); 218 d.seconds = SecFromTime(t); 219 d.ms = msFromTime(t); 220 221 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); 222 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); 223 d.day = WeekDay( d.value ); 224 225 return (d); 226 } 227 function SetUTCFullYear( t, year, mon, date ) { 228 var T = ( t != t ) ? 0 : t; 229 var YEAR = Number(year); 230 var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon ); 231 var DATE = ( date == void 0 ) ? DateFromTime(T) : Number( date ); 232 var DAY = MakeDay( YEAR, MONTH, DATE ); 233 234 return ( TimeClip(MakeDate(DAY, TimeWithinDay(T))) ); 235 } 236