]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.3.8-5.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
;
99 var PST_1900
= TIME_1900
+ 8*msPerHour
;
101 addNewTestCase( new Date( TIME_1900
),
102 "new Date("+TIME_1900
+")",
103 [TIME_1900
,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
105 addNewTestCase( new Date(PST_1900
),
106 "new Date("+PST_1900
+")",
107 [ PST_1900
,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
109 addNewTestCase( new Date( (new Date(TIME_1900
)).toString() ),
110 "new Date(\""+(new Date(TIME_1900
)).toString()+"\")",
111 [TIME_1900
,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
113 addNewTestCase( new Date( (new Date(PST_1900
)).toString() ),
114 "new Date(\""+(new Date(PST_1900
)).toString()+"\")",
115 [ PST_1900
,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
117 addNewTestCase( new Date( (new Date(TIME_1900
)).toUTCString() ),
118 "new Date(\""+(new Date(TIME_1900
)).toUTCString()+"\")",
119 [TIME_1900
,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
121 addNewTestCase( new Date( (new Date(PST_1900
)).toUTCString() ),
122 "new Date(\""+(new Date(PST_1900
)).toUTCString()+"\")",
123 [ PST_1900
,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
126 This test case is incorrect. Need to fix the DaylightSavings functions in
127 shell.js for this to work properly.
129 var DST_START_1998 = UTC( GetSecondSundayInMarch(TimeFromYear(1998)) + 2*msPerHour )
131 addNewTestCase( new Date(DST_START_1998-1),
132 "new Date("+(DST_START_1998-1)+")",
133 [DST_START_1998-1,1998,3,5,0,9,59,59,999,1998,3,5,0,1,59,59,999] );
135 addNewTestCase( new Date(DST_START_1998),
136 "new Date("+DST_START_1998+")",
137 [DST_START_1998,1998,3,5,0,10,0,0,0,1998,3,5,0,3,0,0,0]);
139 var DST_END_1998 = UTC( GetFirstSundayInNovember(TimeFromYear(1998)) + 2*msPerHour );
141 addNewTestCase ( new Date(DST_END_1998-1),
142 "new Date("+(DST_END_1998-1)+")",
143 [DST_END_1998-1,1998,9,25,0,8,59,59,999,1998,9,25,0,1,59,59,999] );
145 addNewTestCase ( new Date(DST_END_1998),
146 "new Date("+DST_END_1998+")",
147 [DST_END_1998,1998,9,25,0,9,0,0,0,1998,9,25,0,1,0,0,0] );
151 function addNewTestCase( DateCase
, DateString
, ResultArray
) {
152 //adjust hard-coded ResultArray for tester's timezone instead of PST
153 adjustResultArray(ResultArray
, 'msMode');
155 item
= testcases
.length
;
157 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", ResultArray
[TIME
], DateCase
.getTime() );
158 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", ResultArray
[TIME
], DateCase
.valueOf() );
159 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", ResultArray
[UTC_YEAR
], DateCase
.getUTCFullYear() );
160 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", ResultArray
[UTC_MONTH
], DateCase
.getUTCMonth() );
161 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", ResultArray
[UTC_DATE
], DateCase
.getUTCDate() );
162 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDay()", ResultArray
[UTC_DAY
], DateCase
.getUTCDay() );
163 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", ResultArray
[UTC_HOURS
], DateCase
.getUTCHours() );
164 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", ResultArray
[UTC_MINUTES
],DateCase
.getUTCMinutes() );
165 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", ResultArray
[UTC_SECONDS
],DateCase
.getUTCSeconds() );
166 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", ResultArray
[UTC_MS
], DateCase
.getUTCMilliseconds() );
167 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", ResultArray
[YEAR
], DateCase
.getFullYear() );
168 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", ResultArray
[MONTH
], DateCase
.getMonth() );
169 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", ResultArray
[DATE
], DateCase
.getDate() );
170 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDay()", ResultArray
[DAY
], DateCase
.getDay() );
171 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", ResultArray
[HOURS
], DateCase
.getHours() );
172 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", ResultArray
[MINUTES
], DateCase
.getMinutes() );
173 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", ResultArray
[SECONDS
], DateCase
.getSeconds() );
174 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", ResultArray
[MS
], DateCase
.getMilliseconds() );
178 for( tc
= 0; tc
< testcases
.length
; tc
++ ) {
180 testcases
[tc
].passed
= writeTestCaseResult(
181 testcases
[tc
].expect
,
182 testcases
[tc
].actual
,
183 testcases
[tc
].description
+" = " +
184 testcases
[tc
].actual
);
188 // all tests must return a boolean value
189 return ( testcases
);