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.35-1.js 24 ECMA Section: 15.9.5.35 Date.prototype.setUTCMonth(mon [,date]) 25 Description: 26 Author: christine (at) netscape.com 27 Date: 12 november 1997 28 */ 29 var SECTION = "15.9.5.35-1"; 30 var VERSION = "ECMA_1"; 31 startTest(); 32 33 writeHeaderToLog( SECTION + " Date.prototype.setUTCMonth(mon [,date] ) "); 34 35 getTestCases(); 36 test(); 37 38 function test() { 39 for ( tc=0; tc < testcases.length; tc++ ) { 40 testcases[tc].passed = writeTestCaseResult( 41 testcases[tc].expect, 42 testcases[tc].actual, 43 testcases[tc].description +" = "+ 44 testcases[tc].actual ); 45 46 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 47 } 48 stopTest(); 49 return ( testcases ); 50 } 51 52 function getTestCases() { 53 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMonth(0);TDATE", 54 UTCDateFromTime(SetUTCMonth(0,0)), 55 LocalDateFromTime(SetUTCMonth(0,0)) ); 56 57 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMonth(11);TDATE", 58 UTCDateFromTime(SetUTCMonth(0,11)), 59 LocalDateFromTime(SetUTCMonth(0,11)) ); 60 61 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMonth(3,4);TDATE", 62 UTCDateFromTime(SetUTCMonth(0,3,4)), 63 LocalDateFromTime(SetUTCMonth(0,3,4)) ); 64 65 } 66 67 function addNewTestCase( DateString, UTCDate, LocalDate) { 68 DateCase = eval( DateString ); 69 70 var item = testcases.length; 71 72 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year; 73 74 testcases[item++] = new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); 75 testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); 76 77 testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); 78 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); 79 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); 80 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() ); 81 testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); 82 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); 83 testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); 84 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); 85 86 testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); 87 testcases[item++] = new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); 88 testcases[item++] = new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); 89 testcases[item++] = new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() ); 90 testcases[item++] = new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); 91 testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); 92 testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); 93 testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); 94 95 DateCase.toString = Object.prototype.toString; 96 97 testcases[item++] = new TestCase( SECTION, 98 DateString+".toString=Object.prototype.toString;"+DateString+".toString()", 99 "[object Date]", 100 DateCase.toString() ); 101 } 102 function MyDate() { 103 this.year = 0; 104 this.month = 0; 105 this.date = 0; 106 this.hours = 0; 107 this.minutes = 0; 108 this.seconds = 0; 109 this.ms = 0; 110 } 111 function LocalDateFromTime(t) { 112 t = LocalTime(t); 113 return ( MyDateFromTime(t) ); 114 } 115 function UTCDateFromTime(t) { 116 return ( MyDateFromTime(t) ); 117 } 118 function MyDateFromTime( t ) { 119 var d = new MyDate(); 120 d.year = YearFromTime(t); 121 d.month = MonthFromTime(t); 122 d.date = DateFromTime(t); 123 d.hours = HourFromTime(t); 124 d.minutes = MinFromTime(t); 125 d.seconds = SecFromTime(t); 126 d.ms = msFromTime(t); 127 128 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); 129 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); 130 d.day = WeekDay( d.value ); 131 132 return (d); 133 } 134 function SetUTCMonth( t, month, date ) { 135 var T = t; 136 var MONTH = Number( month ); 137 var DATE = ( date == void 0) ? DateFromTime(T) : Number( date ); 138 139 var RESULT4 = MakeDay(YearFromTime(T), MONTH, DATE ); 140 var RESULT5 = MakeDate( RESULT4, TimeWithinDay(T)); 141 142 return ( TimeClip(RESULT5) ); 143 } 144