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/
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.
11 * The Original Code is Mozilla Communicator client code, released March
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
23 File Name: 15.9.5.34-1.js
24 ECMA Section: 15.9.5.34 Date.prototype.setMonth(mon [, date ] )
26 If date is not specified, this behaves as if date were specified with the
29 1. Let t be the result of LocalTime(this time value).
30 2. Call ToNumber(date).
31 3. If date is not specified, compute DateFromTime(t); otherwise, call ToNumber(date).
32 4. Compute MakeDay(YearFromTime(t), Result(2), Result(3)).
33 5. Compute UTC(MakeDate(Result(4), TimeWithinDay(t))).
34 6. Set the [[Value]] property of the this value to TimeClip(Result(5)).
35 7. Return the value of the [[Value]] property of the this value.
37 Author: christine@netscape.com
38 Date: 12 november 1997
40 var SECTION = "15.9.5.34-1";
41 var VERSION = "ECMA_1";
44 writeHeaderToLog( SECTION + " Date.prototype.setMonth(mon [, date ] )");
46 var now = (new Date()).valueOf();
53 for ( tc=0; tc < testcases.length; tc++ ) {
54 testcases[tc].passed = writeTestCaseResult(
57 testcases[tc].description +" = "+
58 testcases[tc].actual );
60 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
66 function getFunctionCases() {
67 // some tests for all functions
68 testcases[testcases.length] = new TestCase(
70 "Date.prototype.setMonth.length",
72 Date.prototype.setMonth.length );
74 testcases[testcases.length] = new TestCase(
76 "typeof Date.prototype.setMonth",
78 typeof Date.prototype.setMonth );
83 testcases[testcases.length] = new TestCase(
85 "delete Date.prototype.setMonth",
87 delete Date.prototype.setMonth );
93 function getTestCases() {
94 // regression test for http://scopus.mcom.com/bugsplat/show_bug.cgi?id=112404
96 d.setMonth(1,1,1,1,1,1);
99 "TDATE = new Date(0); TDATE.setMonth(1,1,1,1,1,1); TDATE",
100 UTCDateFromTime(SetMonth(0,1,1)),
101 LocalDateFromTime(SetMonth(0,1,1)) );
106 addNewTestCase( "TDATE = new Date(now); (TDATE).setMonth(11,31); TDATE",
107 UTCDateFromTime(SetMonth(now,11,31)),
108 LocalDateFromTime(SetMonth(now,11,31)) );
112 addNewTestCase( "TDATE = new Date(0);(TDATE).setMonth(0,1);TDATE",
113 UTCDateFromTime(SetMonth(0,0,1)),
114 LocalDateFromTime(SetMonth(0,0,1)) );
116 addNewTestCase( "TDATE = new Date("+TIME_1900+"); "+
117 "(TDATE).setMonth(11,31); TDATE",
118 UTCDateFromTime( SetMonth(TIME_1900,11,31) ),
119 LocalDateFromTime( SetMonth(TIME_1900,11,31) ) );
125 addNewTestCase( "TDATE = new Date(28800000);(TDATE).setMonth(11,23,59,999);TDATE",
126 UTCDateFromTime(SetMonth(28800000,11,23,59,999)),
127 LocalDateFromTime(SetMonth(28800000,11,23,59,999)) );
129 addNewTestCase( "TDATE = new Date(28800000);(TDATE).setMonth(99,99);TDATE",
130 UTCDateFromTime(SetMonth(28800000,99,99)),
131 LocalDateFromTime(SetMonth(28800000,99,99)) );
133 addNewTestCase( "TDATE = new Date(28800000);(TDATE).setMonth(11);TDATE",
134 UTCDateFromTime(SetMonth(28800000,11,0)),
135 LocalDateFromTime(SetMonth(28800000,11,0)) );
137 addNewTestCase( "TDATE = new Date(28800000);(TDATE).setMonth(-11);TDATE",
138 UTCDateFromTime(SetMonth(28800000,-11)),
139 LocalDateFromTime(SetMonth(28800000,-11)) );
143 // addNewTestCase( "TDATE = new Date(); (TDATE).setMonth(11,31); TDATE;"
147 function addNewTestCase( DateString, UTCDate, LocalDate) {
148 DateCase = eval( DateString );
150 var item = testcases.length;
152 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
154 testcases[item++] = new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
155 testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
157 testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
158 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
159 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
160 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
161 testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
162 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
163 testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
164 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
166 testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
167 testcases[item++] = new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
168 testcases[item++] = new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
169 testcases[item++] = new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
170 testcases[item++] = new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
171 testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
172 testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
173 testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
175 DateCase.toString = Object.prototype.toString;
177 testcases[item++] = new TestCase( SECTION,
178 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
180 DateCase.toString() );
191 function LocalDateFromTime(t) {
193 return ( MyDateFromTime(t) );
195 function UTCDateFromTime(t) {
196 return ( MyDateFromTime(t) );
198 function MyDateFromTime( t ) {
199 var d = new MyDate();
200 d.year = YearFromTime(t);
201 d.month = MonthFromTime(t);
202 d.date = DateFromTime(t);
203 d.hours = HourFromTime(t);
204 d.minutes = MinFromTime(t);
205 d.seconds = SecFromTime(t);
206 d.ms = msFromTime(t);
208 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
209 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
210 d.day = WeekDay( d.value );
214 function SetMonth( t, mon, date ) {
215 var TIME = LocalTime(t);
216 var MONTH = Number( mon );
217 var DATE = ( date == void 0 ) ? DateFromTime(TIME) : Number( date );
218 var DAY = MakeDay( YearFromTime(TIME), MONTH, DATE );
219 return ( TimeClip (UTC(MakeDate( DAY, TimeWithinDay(TIME) ))) );