1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 gTestfile = '15.9.5.30-1.js';
42 File Name: 15.9.5.30-1.js
43 ECMA Section: 15.9.5.30 Date.prototype.setHours(hour [, min [, sec [, ms ]]] )
45 If min is not specified, this behaves as if min were specified with the
46 value getMinutes( ). If sec is not specified, this behaves as if sec were
47 specified with the value getSeconds ( ). If ms is not specified, this
48 behaves as if ms were specified with the value getMilliseconds( ).
50 1. Let t be the result of LocalTime(this time value).
51 2. Call ToNumber(hour).
52 3. If min is not specified, compute MinFromTime(t); otherwise, call
54 4. If sec is not specified, compute SecFromTime(t); otherwise, call
56 5. If ms is not specified, compute msFromTime(t); otherwise, call
58 6. Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
59 7. Compute UTC(MakeDate(Day(t), Result(6))).
60 8. Set the [[Value]] property of the this value to TimeClip(Result(7)).
61 9. Return the value of the [[Value]] property of the this value.
63 Author: christine@netscape.com
64 Date: 12 november 1997
66 var SECTION = "15.9.5.30-1";
67 var VERSION = "ECMA_1";
70 writeHeaderToLog( SECTION + " Date.prototype.setHours( hour [, min, sec, ms] )");
72 addNewTestCase( 0,0,0,0,void 0,
73 "TDATE = new Date(0);(TDATE).setHours(0);TDATE" );
75 addNewTestCase( 28800000, 23, 59, 999,void 0,
76 "TDATE = new Date(28800000);(TDATE).setHours(23,59,999);TDATE" );
78 addNewTestCase( 28800000, 999, 999, void 0, void 0,
79 "TDATE = new Date(28800000);(TDATE).setHours(999,999);TDATE" );
81 addNewTestCase( 28800000,999,0, void 0, void 0,
82 "TDATE = new Date(28800000);(TDATE).setHours(999);TDATE" );
84 addNewTestCase( 28800000,-8, void 0, void 0, void 0,
85 "TDATE = new Date(28800000);(TDATE).setHours(-8);TDATE" );
87 addNewTestCase( 946684800000,8760, void 0, void 0, void 0,
88 "TDATE = new Date(946684800000);(TDATE).setHours(8760);TDATE" );
90 addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 999,
91 "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,999)" );
93 addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 1000,
94 "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,1000)" );
98 function addNewTestCase( time, hours, min, sec, ms, DateString) {
99 var UTCDate = UTCDateFromTime( SetHours( time, hours, min, sec, ms ));
100 var LocalDate = LocalDateFromTime( SetHours( time, hours, min, sec, ms ));
102 var DateCase = new Date( time );
104 if ( min == void 0 ) {
105 DateCase.setHours( hours );
107 if ( sec == void 0 ) {
108 DateCase.setHours( hours, min );
110 if ( ms == void 0 ) {
111 DateCase.setHours( hours, min, sec );
113 DateCase.setHours( hours, min, sec, ms );
119 new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
120 new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
122 new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
123 new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
124 new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
125 new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
126 new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
127 new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
128 new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
129 new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
131 new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
132 new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
133 new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
134 new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
135 new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
136 new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
137 new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
138 new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
140 DateCase.toString = Object.prototype.toString;
142 new TestCase( SECTION,
143 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
145 DateCase.toString() );
157 function LocalDateFromTime(t) {
159 return ( MyDateFromTime(t) );
161 function UTCDateFromTime(t) {
162 return ( MyDateFromTime(t) );
164 function MyDateFromTime( t ) {
165 var d = new MyDate();
166 d.year = YearFromTime(t);
167 d.month = MonthFromTime(t);
168 d.date = DateFromTime(t);
169 d.hours = HourFromTime(t);
170 d.minutes = MinFromTime(t);
171 d.seconds = SecFromTime(t);
172 d.ms = msFromTime(t);
174 d.day = WeekDay( t );
175 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
176 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
180 function SetHours( t, hour, min, sec, ms ) {
181 var TIME = LocalTime(t);
182 var HOUR = Number(hour);
183 var MIN = ( min == void 0) ? MinFromTime(TIME) : Number(min);
184 var SEC = ( sec == void 0) ? SecFromTime(TIME) : Number(sec);
185 var MS = ( ms == void 0 ) ? msFromTime(TIME) : Number(ms);
186 var RESULT6 = MakeTime( HOUR,
190 var UTC_TIME = UTC( MakeDate(Day(TIME), RESULT6) );
191 return ( TimeClip(UTC_TIME) );