]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.3.8-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.3.8.js
24 ECMA Section: 15.9.3.8 The Date Constructor
26 Description: The [[Prototype]] property of the newly constructed
27 object is set to the original Date prototype object,
28 the one that is the initial valiue of Date.prototype.
30 The [[Class]] property of the newly constructed object is
33 The [[Value]] property of the newly constructed object is
36 1. Call ToPrimitive(value)
37 2. If Type( Result(1) ) is String, then go to step 5.
38 3. Let V be ToNumber( Result(1) ).
39 4. Set the [[Value]] property of the newly constructed
40 object to TimeClip(V) and return.
41 5. Parse Result(1) as a date, in exactly the same manner
42 as for the parse method. Let V be the time value for
46 Author: christine@netscape.com
52 var VERSION
= "ECMA_1";
54 var SECTION
= "15.9.3.8";
55 var TYPEOF
= "object";
77 // for TCMS, the testcases array must be global.
79 var TITLE
= "Date constructor: new Date( value )";
80 var SECTION
= "15.9.3.8";
81 var VERSION
= "ECMA_1";
84 writeHeaderToLog( SECTION
+" " + TITLE
);
86 testcases
= new Array();
89 // all tests must call a function that returns a boolean value
92 function getTestCases( ) {
93 // all the "ResultArrays" below are hard-coded to Pacific Standard Time values -
94 var TZ_ADJUST
= -TZ_PST
* msPerHour
;
98 addNewTestCase( new Date(0),
100 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
102 addNewTestCase( new Date(1),
104 [1,1970,0,1,4,0,0,0,1,1969,11,31,3,16,0,0,1] );
106 addNewTestCase( new Date(true),
108 [1,1970,0,1,4,0,0,0,1,1969,11,31,3,16,0,0,1] );
110 addNewTestCase( new Date(false),
112 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
114 addNewTestCase( new Date( (new Date(0)).toString() ),
115 "new Date(\""+ (new Date(0)).toString()+"\" )",
116 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
118 // addNewTestCase( "new Date(\""+ (new Date(0)).toLocaleString()+"\")", [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
120 addNewTestCase( new Date((new Date(0)).toUTCString()),
121 "new Date(\""+ (new Date(0)).toUTCString()+"\" )",
122 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
124 addNewTestCase( new Date((new Date(1)).toString()),
125 "new Date(\""+ (new Date(1)).toString()+"\" )",
126 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
128 addNewTestCase( new Date( TZ_ADJUST ),
129 "new Date(" + TZ_ADJUST+")",
130 [TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
132 addNewTestCase( new Date((new Date(TZ_ADJUST)).toString()),
133 "new Date(\""+ (new Date(TZ_ADJUST)).toString()+"\")",
134 [TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
136 // addNewTestCase( "new Date(\""+ (new Date(TZ_ADJUST)).toLocaleString()+"\")",[TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
138 addNewTestCase( new Date( (new Date(TZ_ADJUST)).toUTCString() ),
139 "new Date(\""+ (new Date(TZ_ADJUST)).toUTCString()+"\")",
140 [TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
144 addNewTestCase( new Date(TIME_2000+TZ_ADJUST),
145 "new Date(" +(TIME_2000+TZ_ADJUST)+")",
146 [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
148 addNewTestCase( new Date(TIME_2000),
149 "new Date(" +TIME_2000+")",
150 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
152 addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toString()),
153 "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toString()+"\")",
154 [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
156 addNewTestCase( new Date((new Date(TIME_2000)).toString()),
157 "new Date(\"" +(new Date(TIME_2000)).toString()+"\")",
158 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
160 // addNewTestCase( "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toLocaleString()+"\")", [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
161 // addNewTestCase( "new Date(\"" +(new Date(TIME_2000)).toLocaleString()+"\")", [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
163 addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toUTCString()),
164 "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toUTCString()+"\")",
165 [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
167 addNewTestCase( new Date( (new Date(TIME_2000)).toUTCString()),
168 "new Date(\"" +(new Date(TIME_2000)).toUTCString()+"\")",
169 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
171 // Dates around Feb 29, 2000
173 var UTC_FEB_29_2000 = TIME_2000 + 31*msPerDay + 28*msPerDay;
174 var PST_FEB_29_2000 = UTC_FEB_29_2000 + TZ_ADJUST;
176 addNewTestCase( new Date(UTC_FEB_29_2000),
177 "new Date("+UTC_FEB_29_2000+")",
178 [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
180 addNewTestCase( new Date(PST_FEB_29_2000),
181 "new Date("+PST_FEB_29_2000+")",
182 [PST_FEB_29_2000,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
184 addNewTestCase( new Date( (new Date(UTC_FEB_29_2000)).toString() ),
185 "new Date(\""+(new Date(UTC_FEB_29_2000)).toString()+"\")",
186 [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
188 addNewTestCase( new Date( (new Date(PST_FEB_29_2000)).toString() ),
189 "new Date(\""+(new Date(PST_FEB_29_2000)).toString()+"\")",
190 [PST_FEB_29_2000,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
192 // Parsing toLocaleString() is not guaranteed by ECMA.
193 // addNewTestCase( "new Date(\""+(new Date(UTC_FEB_29_2000)).toLocaleString()+"\")", [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
194 // addNewTestCase( "new Date(\""+(new Date(PST_FEB_29_2000)).toLocaleString()+"\")", [PST_FEB_29_2000,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
196 addNewTestCase( new Date( (new Date(UTC_FEB_29_2000)).toGMTString() ),
197 "new Date(\""+(new Date(UTC_FEB_29_2000)).toGMTString()+"\")",
198 [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
200 addNewTestCase( new Date( (new Date(PST_FEB_29_2000)).toGMTString() ),
201 "new Date(\""+(new Date(PST_FEB_29_2000)).toGMTString()+"\")",
202 [PST_FEB_29_2000,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
206 var PST_1900 = TIME_1900 + 8*msPerHour;
208 addNewTestCase( new Date( TIME_1900 ),
209 "new Date("+TIME_1900+")",
210 [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
212 addNewTestCase( new Date(PST_1900),
213 "new Date("+PST_1900+")",
214 [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
216 addNewTestCase( new Date( (new Date(TIME_1900)).toString() ),
217 "new Date(\""+(new Date(TIME_1900)).toString()+"\")",
218 [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
220 addNewTestCase( new Date( (new Date(PST_1900)).toString() ),
221 "new Date(\""+(new Date(PST_1900 )).toString()+"\")",
222 [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
224 addNewTestCase( new Date( (new Date(TIME_1900)).toUTCString() ),
225 "new Date(\""+(new Date(TIME_1900)).toUTCString()+"\")",
226 [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
228 addNewTestCase( new Date( (new Date(PST_1900)).toUTCString() ),
229 "new Date(\""+(new Date(PST_1900 )).toUTCString()+"\")",
230 [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
232 // addNewTestCase( "new Date(\""+(new Date(TIME_1900)).toLocaleString()+"\")", [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
233 // addNewTestCase( "new Date(\""+(new Date(PST_1900 )).toLocaleString()+"\")", [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
236 This test case is incorrect. Need to fix the DaylightSavings functions in
237 shell.js for this to work properly.
239 var DST_START_1998 = UTC( GetSecondSundayInMarch(TimeFromYear(1998)) + 2*msPerHour )
241 addNewTestCase( new Date(DST_START_1998-1),
242 "new Date("+(DST_START_1998-1)+")",
243 [DST_START_1998-1,1998,3,5,0,9,59,59,999,1998,3,5,0,1,59,59,999] );
245 addNewTestCase( new Date(DST_START_1998),
246 "new Date("+DST_START_1998+")",
247 [DST_START_1998,1998,3,5,0,10,0,0,0,1998,3,5,0,3,0,0,0]);
249 var DST_END_1998 = UTC( GetFirstSundayInNovember(TimeFromYear(1998)) + 2*msPerHour );
251 addNewTestCase ( new Date(DST_END_1998-1),
252 "new Date("+(DST_END_1998-1)+")",
253 [DST_END_1998-1,1998,9,25,0,8,59,59,999,1998,9,25,0,1,59,59,999] );
255 addNewTestCase ( new Date(DST_END_1998),
256 "new Date("+DST_END_1998+")",
257 [DST_END_1998,1998,9,25,0,9,0,0,0,1998,9,25,0,1,0,0,0] );
261 function addNewTestCase( DateCase
, DateString
, ResultArray
) {
262 //adjust hard-coded ResultArray for tester's timezone instead of PST
263 adjustResultArray(ResultArray
, 'msMode');
265 item
= testcases
.length
;
267 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", ResultArray
[TIME
], DateCase
.getTime() );
268 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", ResultArray
[TIME
], DateCase
.valueOf() );
269 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", ResultArray
[UTC_YEAR
], DateCase
.getUTCFullYear() );
270 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", ResultArray
[UTC_MONTH
], DateCase
.getUTCMonth() );
271 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", ResultArray
[UTC_DATE
], DateCase
.getUTCDate() );
272 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDay()", ResultArray
[UTC_DAY
], DateCase
.getUTCDay() );
273 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", ResultArray
[UTC_HOURS
], DateCase
.getUTCHours() );
274 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", ResultArray
[UTC_MINUTES
],DateCase
.getUTCMinutes() );
275 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", ResultArray
[UTC_SECONDS
],DateCase
.getUTCSeconds() );
276 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", ResultArray
[UTC_MS
], DateCase
.getUTCMilliseconds() );
277 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", ResultArray
[YEAR
], DateCase
.getFullYear() );
278 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", ResultArray
[MONTH
], DateCase
.getMonth() );
279 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", ResultArray
[DATE
], DateCase
.getDate() );
280 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDay()", ResultArray
[DAY
], DateCase
.getDay() );
281 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", ResultArray
[HOURS
], DateCase
.getHours() );
282 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", ResultArray
[MINUTES
], DateCase
.getMinutes() );
283 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", ResultArray
[SECONDS
], DateCase
.getSeconds() );
284 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", ResultArray
[MS
], DateCase
.getMilliseconds() );
288 for( tc
= 0; tc
< testcases
.length
; tc
++ ) {
290 testcases
[tc
].passed
= writeTestCaseResult(
291 testcases
[tc
].expect
,
292 testcases
[tc
].actual
,
293 testcases
[tc
].description
+" = " +
294 testcases
[tc
].actual
);
298 // all tests must return a boolean value
299 return ( testcases
);