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.30-1.js
24 ECMA Section: 15.9.5.30 Date.prototype.setHours(hour [, min [, sec [, ms ]]] )
26 If min is not specified, this behaves as if min were specified with the
27 value getMinutes( ). If sec is not specified, this behaves as if sec were
28 specified with the value getSeconds ( ). If ms is not specified, this
29 behaves as if ms were specified with the value getMilliseconds( ).
31 1. Let t be the result of LocalTime(this time value).
32 2. Call ToNumber(hour).
33 3. If min is not specified, compute MinFromTime(t); otherwise, call
35 4. If sec is not specified, compute SecFromTime(t); otherwise, call
37 5. If ms is not specified, compute msFromTime(t); otherwise, call
39 6. Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
40 7. Compute UTC(MakeDate(Day(t), Result(6))).
41 8. Set the [[Value]] property of the this value to TimeClip(Result(7)).
42 9. Return the value of the [[Value]] property of the this value.
44 Author: christine@netscape.com
45 Date: 12 november 1997
47 var SECTION = "15.9.5.30-1";
48 var VERSION = "ECMA_1";
51 writeHeaderToLog( SECTION + " Date.prototype.setHours( hour [, min, sec, ms] )");
57 for ( tc=0; tc < testcases.length; tc++ ) {
58 testcases[tc].passed = writeTestCaseResult(
61 testcases[tc].description +" = "+
62 testcases[tc].actual );
64 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
70 function getTestCases() {
71 addNewTestCase( 0,0,0,0,void 0,
72 "TDATE = new Date(0);(TDATE).setHours(0);TDATE" );
74 addNewTestCase( 28800000, 23, 59, 999,void 0,
75 "TDATE = new Date(28800000);(TDATE).setHours(23,59,999);TDATE" );
77 addNewTestCase( 28800000, 999, 999, void 0, void 0,
78 "TDATE = new Date(28800000);(TDATE).setHours(999,999);TDATE" );
80 addNewTestCase( 28800000,999,0, void 0, void 0,
81 "TDATE = new Date(28800000);(TDATE).setHours(999);TDATE" );
83 addNewTestCase( 28800000,-8, void 0, void 0, void 0,
84 "TDATE = new Date(28800000);(TDATE).setHours(-8);TDATE" );
86 addNewTestCase( 946684800000,8760, void 0, void 0, void 0,
87 "TDATE = new Date(946684800000);(TDATE).setHours(8760);TDATE" );
89 addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 999,
90 "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,999)" );
92 addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 1000,
93 "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,1000)" );
97 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setHours(59,999);TDATE",
98 UTCDateFromTime(SetHours(-2208988800000,59,999)),
99 LocalDateFromTime(SetHours(-2208988800000,59,999)) );
101 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
102 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)),
103 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)) );
105 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456);TDATE",
106 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456)),
107 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456)) );
109 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(-123456);TDATE",
110 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)),
111 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)) );
113 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMilliseconds(-999);TDATE",
114 UTCDateFromTime(SetUTCMilliseconds(0,-999)),
115 LocalDateFromTime(SetUTCMilliseconds(0,-999)) );
119 function addNewTestCase( time, hours, min, sec, ms, DateString) {
120 var UTCDate = UTCDateFromTime( SetHours( time, hours, min, sec, ms ));
121 var LocalDate = LocalDateFromTime( SetHours( time, hours, min, sec, ms ));
123 var DateCase = new Date( time );
125 if ( min == void 0 ) {
126 DateCase.setHours( hours );
128 if ( sec == void 0 ) {
129 DateCase.setHours( hours, min );
131 if ( ms == void 0 ) {
132 DateCase.setHours( hours, min, sec );
134 DateCase.setHours( hours, min, sec, ms );
140 var item = testcases.length;
142 testcases[item++] = new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
143 testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
145 testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
146 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
147 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
148 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
149 testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
150 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
151 testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
152 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
154 testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
155 testcases[item++] = new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
156 testcases[item++] = new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
157 testcases[item++] = new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
158 testcases[item++] = new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
159 testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
160 testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
161 testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
163 DateCase.toString = Object.prototype.toString;
165 testcases[item++] = new TestCase( SECTION,
166 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
168 DateCase.toString() );
180 function LocalDateFromTime(t) {
182 return ( MyDateFromTime(t) );
184 function UTCDateFromTime(t) {
185 return ( MyDateFromTime(t) );
187 function MyDateFromTime( t ) {
188 var d = new MyDate();
189 d.year = YearFromTime(t);
190 d.month = MonthFromTime(t);
191 d.date = DateFromTime(t);
192 d.hours = HourFromTime(t);
193 d.minutes = MinFromTime(t);
194 d.seconds = SecFromTime(t);
195 d.ms = msFromTime(t);
197 d.day = WeekDay( t );
198 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
199 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
203 function SetHours( t, hour, min, sec, ms ) {
204 var TIME = LocalTime(t);
205 var HOUR = Number(hour);
206 var MIN = ( min == void 0) ? MinFromTime(TIME) : Number(min);
207 var SEC = ( sec == void 0) ? SecFromTime(TIME) : Number(sec);
208 var MS = ( ms == void 0 ) ? msFromTime(TIME) : Number(ms);
209 var RESULT6 = MakeTime( HOUR,
213 var UTC_TIME = UTC( MakeDate(Day(TIME), RESULT6) );
214 return ( TimeClip(UTC_TIME) );