]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.5.31-1.js
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.31-1.js
24 ECMA Section: 15.9.5.31 Date.prototype.setUTCHours(hour [, min [, sec [, ms ]]] )
26 If min is not specified, this behaves as if min were specified with the value getUTCMinutes( ).
27 If sec is not specified, this behaves as if sec were specified with the value getUTCSeconds ( ).
28 If ms is not specified, this behaves as if ms were specified with the value getUTCMilliseconds( ).
30 1.Let t be this time value.
31 2.Call ToNumber(hour).
32 3.If min is not specified, compute MinFromTime(t); otherwise, call ToNumber(min).
33 4.If sec is not specified, compute SecFromTime(t); otherwise, call ToNumber(sec).
34 5.If ms is not specified, compute msFromTime(t); otherwise, call ToNumber(ms).
35 6.Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
36 7.Compute MakeDate(Day(t), Result(6)).
37 8.Set the [[Value]] property of the this value to TimeClip(Result(7)).
39 1.Return the value of the [[Value]] property of the this value.
40 Author: christine@netscape.com
41 Date: 12 november 1997
43 var SECTION
= "15.9.5.31-1";
44 var VERSION
= "ECMA_1";
47 writeHeaderToLog( SECTION
+ " Date.prototype.setUTCHours(hour [, min [, sec [, ms ]]] )");
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 getTestCases() {
67 addNewTestCase( 0, 0, void 0, void 0, void 0,
68 "TDATE = new Date(0);(TDATE).setUTCHours(0);TDATE",
69 UTCDateFromTime(SetUTCHours(0,0,0,0)),
70 LocalDateFromTime(SetUTCHours(0,0,0,0)) );
72 addNewTestCase( 28800000, 23, 59, 999, void 0,
73 "TDATE = new Date(28800000);(TDATE).setUTCHours(23,59,999);TDATE",
74 UTCDateFromTime(SetUTCHours(28800000,23,59,999)),
75 LocalDateFromTime(SetUTCHours(28800000,23,59,999)) );
77 addNewTestCase( 28800000,999,999, void 0, void 0,
78 "TDATE = new Date(28800000);(TDATE).setUTCHours(999,999);TDATE",
79 UTCDateFromTime(SetUTCHours(28800000,999,999)),
80 LocalDateFromTime(SetUTCHours(28800000,999,999)) );
82 addNewTestCase( 28800000, 999, void 0, void 0, void 0,
83 "TDATE = new Date(28800000);(TDATE).setUTCHours(999);TDATE",
84 UTCDateFromTime(SetUTCHours(28800000,999,0)),
85 LocalDateFromTime(SetUTCHours(28800000,999,0)) );
87 addNewTestCase( 28800000, -8670, void 0, void 0, void 0,
88 "TDATE = new Date(28800000);(TDATE).setUTCHours(-8670);TDATE",
89 UTCDateFromTime(SetUTCHours(28800000,-8670)),
90 LocalDateFromTime(SetUTCHours(28800000,-8670)) );
92 addNewTestCase( 946684800000, 1234567, void 0, void 0, void 0,
93 "TDATE = new Date(946684800000);(TDATE).setUTCHours(1234567);TDATE",
94 UTCDateFromTime(SetUTCHours(946684800000,1234567)),
95 LocalDateFromTime(SetUTCHours(946684800000,1234567)) );
97 addNewTestCase( -2208988800000, 59, 999, void 0, void 0,
98 "TDATE = new Date(-2208988800000);(TDATE).setUTCHours(59,999);TDATE",
99 UTCDateFromTime(SetUTCHours(-2208988800000,59,999)),
100 LocalDateFromTime(SetUTCHours(-2208988800000,59,999)) );
102 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
103 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)),
104 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)) );
106 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456);TDATE",
107 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456)),
108 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456)) );
110 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(-123456);TDATE",
111 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)),
112 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)) );
114 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMilliseconds(-999);TDATE",
115 UTCDateFromTime(SetUTCMilliseconds(0,-999)),
116 LocalDateFromTime(SetUTCMilliseconds(0,-999)) );
120 function addNewTestCase( time
, hours
, min
, sec
, ms
, DateString
, UTCDate
, LocalDate
) {
122 DateCase
= new Date(time
);
123 if ( min
== void 0 ) {
124 DateCase
.setUTCHours( hours
);
126 if ( sec
== void 0 ) {
127 DateCase
.setUTCHours( hours
, min
);
129 if ( ms
== void 0 ) {
130 DateCase
.setUTCHours( hours
, min
, sec
);
132 DateCase
.setUTCHours( hours
, min
, sec
, ms
);
137 var item
= testcases
.length
;
139 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
141 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", UTCDate
.value
, DateCase
.getTime() );
142 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", UTCDate
.value
, DateCase
.valueOf() );
144 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", UTCDate
.year
, DateCase
.getUTCFullYear() );
145 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", UTCDate
.month
, DateCase
.getUTCMonth() );
146 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", UTCDate
.date
, DateCase
.getUTCDate() );
147 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDay()", UTCDate
.day
, DateCase
.getUTCDay() );
148 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", UTCDate
.hours
, DateCase
.getUTCHours() );
149 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", UTCDate
.minutes
,DateCase
.getUTCMinutes() );
150 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", UTCDate
.seconds
,DateCase
.getUTCSeconds() );
151 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", UTCDate
.ms
, DateCase
.getUTCMilliseconds() );
153 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", LocalDate
.year
, DateCase
.getFullYear() );
154 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", LocalDate
.month
, DateCase
.getMonth() );
155 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", LocalDate
.date
, DateCase
.getDate() );
156 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDay()", LocalDate
.day
, DateCase
.getDay() );
157 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", LocalDate
.hours
, DateCase
.getHours() );
158 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", LocalDate
.minutes
, DateCase
.getMinutes() );
159 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", LocalDate
.seconds
, DateCase
.getSeconds() );
160 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", LocalDate
.ms
, DateCase
.getMilliseconds() );
162 DateCase
.toString
= Object
.prototype.toString
;
164 testcases
[item
++] = new TestCase( SECTION
,
165 DateString
+".toString=Object.prototype.toString;"+DateString
+".toString()",
167 DateCase
.toString() );
178 function LocalDateFromTime(t
) {
180 return ( MyDateFromTime(t
) );
182 function UTCDateFromTime(t
) {
183 return ( MyDateFromTime(t
) );
185 function MyDateFromTime( t
) {
186 var d
= new MyDate();
187 d
.year
= YearFromTime(t
);
188 d
.month
= MonthFromTime(t
);
189 d
.date
= DateFromTime(t
);
190 d
.hours
= HourFromTime(t
);
191 d
.minutes
= MinFromTime(t
);
192 d
.seconds
= SecFromTime(t
);
193 d
.ms
= msFromTime(t
);
195 d
.time
= MakeTime( d
.hours
, d
.minutes
, d
.seconds
, d
.ms
);
196 d
.value
= TimeClip( MakeDate( MakeDay( d
.year
, d
.month
, d
.date
), d
.time
) );
197 d
.day
= WeekDay( d
.value
);
201 function SetUTCHours( t
, hour
, min
, sec
, ms
) {
203 var HOUR
= Number(hour
);
204 var MIN
= ( min
== void 0) ? MinFromTime(TIME
) : Number(min
);
205 var SEC
= ( sec
== void 0) ? SecFromTime(TIME
) : Number(sec
);
206 var MS
= ( ms
== void 0 ) ? msFromTime(TIME
) : Number(ms
);
207 var RESULT6
= MakeTime( HOUR
,
211 return ( TimeClip(MakeDate(Day(TIME
), RESULT6
)) );