]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/mozilla/ecma/Date/15.9.5.30-1.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / ecma / Date / 15.9.5.30-1.js
CommitLineData
b37bf2e1
A
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.30-1.js
24 ECMA Section: 15.9.5.30 Date.prototype.setHours(hour [, min [, sec [, ms ]]] )
25 Description:
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( ).
30
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
34 ToNumber(min).
35 4. If sec is not specified, compute SecFromTime(t); otherwise, call
36 ToNumber(sec).
37 5. If ms is not specified, compute msFromTime(t); otherwise, call
38 ToNumber(ms).
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.
43
44 Author: christine@netscape.com
45 Date: 12 november 1997
46*/
47 var SECTION = "15.9.5.30-1";
48 var VERSION = "ECMA_1";
49 startTest();
50
51 writeHeaderToLog( SECTION + " Date.prototype.setHours( hour [, min, sec, ms] )");
52
53 getTestCases();
54 test();
55
56function 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
70function getTestCases() {
71 addNewTestCase( 0,0,0,0,void 0,
72 "TDATE = new Date(0);(TDATE).setHours(0);TDATE" );
73
74 addNewTestCase( 28800000, 23, 59, 999,void 0,
75 "TDATE = new Date(28800000);(TDATE).setHours(23,59,999);TDATE" );
76
77 addNewTestCase( 28800000, 999, 999, void 0, void 0,
78 "TDATE = new Date(28800000);(TDATE).setHours(999,999);TDATE" );
79
80 addNewTestCase( 28800000,999,0, void 0, void 0,
81 "TDATE = new Date(28800000);(TDATE).setHours(999);TDATE" );
82
83 addNewTestCase( 28800000,-8, void 0, void 0, void 0,
84 "TDATE = new Date(28800000);(TDATE).setHours(-8);TDATE" );
85
86 addNewTestCase( 946684800000,8760, void 0, void 0, void 0,
87 "TDATE = new Date(946684800000);(TDATE).setHours(8760);TDATE" );
88
89 addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 999,
90 "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,999)" );
91
92 addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 1000,
93 "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,1000)" );
94
95
96/*
97 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setHours(59,999);TDATE",
98 UTCDateFromTime(SetHours(-2208988800000,59,999)),
99 LocalDateFromTime(SetHours(-2208988800000,59,999)) );
100
101 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
102 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)),
103 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)) );
104
105 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456);TDATE",
106 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456)),
107 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456)) );
108
109 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(-123456);TDATE",
110 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)),
111 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)) );
112
113 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMilliseconds(-999);TDATE",
114 UTCDateFromTime(SetUTCMilliseconds(0,-999)),
115 LocalDateFromTime(SetUTCMilliseconds(0,-999)) );
116*/
117
118}
119function 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 ));
122
123 var DateCase = new Date( time );
124
125 if ( min == void 0 ) {
126 DateCase.setHours( hours );
127 } else {
128 if ( sec == void 0 ) {
129 DateCase.setHours( hours, min );
130 } else {
131 if ( ms == void 0 ) {
132 DateCase.setHours( hours, min, sec );
133 } else {
134 DateCase.setHours( hours, min, sec, ms );
135 }
136 }
137 }
138
139
140 var item = testcases.length;
141
142 testcases[item++] = new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
143 testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
144
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() );
153
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() );
162
163 DateCase.toString = Object.prototype.toString;
164
165 testcases[item++] = new TestCase( SECTION,
166 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
167 "[object Date]",
168 DateCase.toString() );
169}
170
171function MyDate() {
172 this.year = 0;
173 this.month = 0;
174 this.date = 0;
175 this.hours = 0;
176 this.minutes = 0;
177 this.seconds = 0;
178 this.ms = 0;
179}
180function LocalDateFromTime(t) {
181 t = LocalTime(t);
182 return ( MyDateFromTime(t) );
183}
184function UTCDateFromTime(t) {
185 return ( MyDateFromTime(t) );
186}
187function 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);
196
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 ) );
200
201 return (d);
202}
203function 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,
210 MIN,
211 SEC,
212 MS );
213 var UTC_TIME = UTC( MakeDate(Day(TIME), RESULT6) );
214 return ( TimeClip(UTC_TIME) );
215}