]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.3.8-2.js
4cfcb0470e6e9ea2269640358680312387b6fb54
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
;
96 addNewTestCase( new Date((new Date(0)).toUTCString()),
97 "new Date(\""+ (new Date(0)).toUTCString()+"\" )",
98 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
100 addNewTestCase( new Date((new Date(1)).toString()),
101 "new Date(\""+ (new Date(1)).toString()+"\" )",
102 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
104 addNewTestCase( new Date( TZ_ADJUST
),
105 "new Date(" + TZ_ADJUST
+")",
106 [TZ_ADJUST
,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
108 addNewTestCase( new Date((new Date(TZ_ADJUST
)).toString()),
109 "new Date(\""+ (new Date(TZ_ADJUST
)).toString()+"\")",
110 [TZ_ADJUST
,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
113 addNewTestCase( new Date( (new Date(TZ_ADJUST
)).toUTCString() ),
114 "new Date(\""+ (new Date(TZ_ADJUST
)).toUTCString()+"\")",
115 [TZ_ADJUST
,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
119 addNewTestCase( new Date(TIME_2000+TZ_ADJUST),
120 "new Date(" +(TIME_2000+TZ_ADJUST)+")",
121 [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
123 addNewTestCase( new Date(TIME_2000),
124 "new Date(" +TIME_2000+")",
125 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
127 addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toString()),
128 "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toString()+"\")",
129 [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
131 addNewTestCase( new Date((new Date(TIME_2000)).toString()),
132 "new Date(\"" +(new Date(TIME_2000)).toString()+"\")",
133 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
135 // 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] );
136 // 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] );
138 addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toUTCString()),
139 "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toUTCString()+"\")",
140 [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
142 addNewTestCase( new Date( (new Date(TIME_2000)).toUTCString()),
143 "new Date(\"" +(new Date(TIME_2000)).toUTCString()+"\")",
144 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
146 // Dates around Feb 29, 2000
148 var UTC_FEB_29_2000 = TIME_2000 + 31*msPerDay + 28*msPerDay;
149 var PST_FEB_29_2000 = UTC_FEB_29_2000 + TZ_ADJUST;
151 addNewTestCase( new Date(UTC_FEB_29_2000),
152 "new Date("+UTC_FEB_29_2000+")",
153 [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
155 addNewTestCase( new Date(PST_FEB_29_2000),
156 "new Date("+PST_FEB_29_2000+")",
157 [PST_FEB_29_2000,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
159 addNewTestCase( new Date( (new Date(UTC_FEB_29_2000)).toString() ),
160 "new Date(\""+(new Date(UTC_FEB_29_2000)).toString()+"\")",
161 [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
163 addNewTestCase( new Date( (new Date(PST_FEB_29_2000)).toString() ),
164 "new Date(\""+(new Date(PST_FEB_29_2000)).toString()+"\")",
165 [PST_FEB_29_2000,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
167 // Parsing toLocaleString() is not guaranteed by ECMA.
168 // 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] );
169 // 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] );
171 addNewTestCase( new Date( (new Date(UTC_FEB_29_2000)).toGMTString() ),
172 "new Date(\""+(new Date(UTC_FEB_29_2000)).toGMTString()+"\")",
173 [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
175 addNewTestCase( new Date( (new Date(PST_FEB_29_2000)).toGMTString() ),
176 "new Date(\""+(new Date(PST_FEB_29_2000)).toGMTString()+"\")",
177 [PST_FEB_29_2000,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
181 var PST_1900 = TIME_1900 + 8*msPerHour;
183 addNewTestCase( new Date( TIME_1900 ),
184 "new Date("+TIME_1900+")",
185 [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
187 addNewTestCase( new Date(PST_1900),
188 "new Date("+PST_1900+")",
189 [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
191 addNewTestCase( new Date( (new Date(TIME_1900)).toString() ),
192 "new Date(\""+(new Date(TIME_1900)).toString()+"\")",
193 [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
195 addNewTestCase( new Date( (new Date(PST_1900)).toString() ),
196 "new Date(\""+(new Date(PST_1900 )).toString()+"\")",
197 [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
199 addNewTestCase( new Date( (new Date(TIME_1900)).toUTCString() ),
200 "new Date(\""+(new Date(TIME_1900)).toUTCString()+"\")",
201 [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
203 addNewTestCase( new Date( (new Date(PST_1900)).toUTCString() ),
204 "new Date(\""+(new Date(PST_1900 )).toUTCString()+"\")",
205 [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
207 // 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] );
208 // 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] );
211 This test case is incorrect. Need to fix the DaylightSavings functions in
212 shell.js for this to work properly.
214 var DST_START_1998 = UTC( GetSecondSundayInMarch(TimeFromYear(1998)) + 2*msPerHour )
216 addNewTestCase( new Date(DST_START_1998-1),
217 "new Date("+(DST_START_1998-1)+")",
218 [DST_START_1998-1,1998,3,5,0,9,59,59,999,1998,3,5,0,1,59,59,999] );
220 addNewTestCase( new Date(DST_START_1998),
221 "new Date("+DST_START_1998+")",
222 [DST_START_1998,1998,3,5,0,10,0,0,0,1998,3,5,0,3,0,0,0]);
224 var DST_END_1998 = UTC( GetFirstSundayInNovember(TimeFromYear(1998)) + 2*msPerHour );
226 addNewTestCase ( new Date(DST_END_1998-1),
227 "new Date("+(DST_END_1998-1)+")",
228 [DST_END_1998-1,1998,9,25,0,8,59,59,999,1998,9,25,0,1,59,59,999] );
230 addNewTestCase ( new Date(DST_END_1998),
231 "new Date("+DST_END_1998+")",
232 [DST_END_1998,1998,9,25,0,9,0,0,0,1998,9,25,0,1,0,0,0] );
236 function addNewTestCase( DateCase
, DateString
, ResultArray
) {
237 //adjust hard-coded ResultArray for tester's timezone instead of PST
238 adjustResultArray(ResultArray
, 'msMode');
240 item
= testcases
.length
;
242 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", ResultArray
[TIME
], DateCase
.getTime() );
243 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", ResultArray
[TIME
], DateCase
.valueOf() );
244 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", ResultArray
[UTC_YEAR
], DateCase
.getUTCFullYear() );
245 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", ResultArray
[UTC_MONTH
], DateCase
.getUTCMonth() );
246 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", ResultArray
[UTC_DATE
], DateCase
.getUTCDate() );
247 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDay()", ResultArray
[UTC_DAY
], DateCase
.getUTCDay() );
248 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", ResultArray
[UTC_HOURS
], DateCase
.getUTCHours() );
249 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", ResultArray
[UTC_MINUTES
],DateCase
.getUTCMinutes() );
250 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", ResultArray
[UTC_SECONDS
],DateCase
.getUTCSeconds() );
251 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", ResultArray
[UTC_MS
], DateCase
.getUTCMilliseconds() );
252 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", ResultArray
[YEAR
], DateCase
.getFullYear() );
253 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", ResultArray
[MONTH
], DateCase
.getMonth() );
254 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", ResultArray
[DATE
], DateCase
.getDate() );
255 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDay()", ResultArray
[DAY
], DateCase
.getDay() );
256 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", ResultArray
[HOURS
], DateCase
.getHours() );
257 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", ResultArray
[MINUTES
], DateCase
.getMinutes() );
258 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", ResultArray
[SECONDS
], DateCase
.getSeconds() );
259 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", ResultArray
[MS
], DateCase
.getMilliseconds() );
263 for( tc
= 0; tc
< testcases
.length
; tc
++ ) {
265 testcases
[tc
].passed
= writeTestCaseResult(
266 testcases
[tc
].expect
,
267 testcases
[tc
].actual
,
268 testcases
[tc
].description
+" = " +
269 testcases
[tc
].actual
);
273 // all tests must return a boolean value
274 return ( testcases
);