]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.3.1-2.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.1.js
24 ECMA Section: 15.9.3.1 new Date (year, month, date, hours, minutes, seconds, ms)
25 Description: The [[Prototype]] property of the newly constructed
26 object is set to the original Date prototype object,
27 the one that is the initial value of Date.prototype.
29 The [[Class]] property of the newly constructed object
31 1. Call ToNumber(year)
32 2. Call ToNumber(month)
33 3. Call ToNumber(date)
34 4. Call ToNumber(hours)
35 5. Call ToNumber(minutes)
36 6. Call ToNumber(seconds)
38 8. If Result(1) is NaN and 0 <= ToInteger(Result(1)) <=
39 99, Result(8) is 1900+ToInteger(Result(1)); otherwise,
40 Result(8) is Result(1)
41 9. Compute MakeDay(Result(8), Result(2), Result(3)
42 10. Compute MakeTime(Result(4), Result(5), Result(6),
44 11. Compute MakeDate(Result(9), Result(10))
45 12. Set the [[Value]] property of the newly constructed
46 object to TimeClip(UTC(Result(11))).
49 This tests the returned value of a newly constructed
52 Author: christine@netscape.com
56 var SECTION
= "15.9.3.1";
57 var VERSION
= "ECMA_1";
59 var TITLE
= "new Date( year, month, date, hours, minutes, seconds, ms )";
80 writeHeaderToLog( SECTION
+ " "+ TITLE
);
82 var testcases
= new Array();
87 function getTestCases( ) {
88 // all the "ResultArrays" below are hard-coded to Pacific Standard Time values -
89 var TZ_ADJUST
= TZ_PST
* msPerHour
;
93 addNewTestCase( new Date( 1999,11,31,15,59,59,999),
94 "new Date( 1999,11,31,15,59,59,999)",
95 [TIME_2000
-1,1999,11,31,5,23,59,59,999,1999,11,31,5,15,59,59,999] );
97 addNewTestCase( new Date( 1999,11,31,16,0,0,0),
98 "new Date( 1999,11,31,16,0,0,0)",
99 [TIME_2000
,2000,0,1,6,0,0,0,0,1999,11,31,5, 16,0,0,0] );
101 addNewTestCase( new Date( 1999,11,31,23,59,59,999),
102 "new Date( 1999,11,31,23,59,59,999)",
103 [TIME_2000
-TZ_ADJUST
-1,2000,0,1,6,7,59,59,999,1999,11,31,5,23,59,59,999] );
105 addNewTestCase( new Date( 2000,0,1,0,0,0,0),
106 "new Date( 2000,0,1,0,0,0,0)",
107 [TIME_2000
-TZ_ADJUST
,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
109 addNewTestCase( new Date( 2000,0,1,0,0,0,1),
110 "new Date( 2000,0,1,0,0,0,1)",
111 [TIME_2000
-TZ_ADJUST
+1,2000,0,1,6,8,0,0,1,2000,0,1,6,0,0,0,1] );
113 // Dates around 29 Feb 2000
115 var UTC_FEB_29_2000 = TIME_2000 + ( 30 * msPerDay ) + ( 29 * msPerDay );
117 addNewTestCase( new Date(2000,1,28,16,0,0,0),
118 "new Date(2000,1,28,16,0,0,0)",
119 [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
121 addNewTestCase( new Date(2000,1,29,0,0,0,0),
122 "new Date(2000,1,29,0,0,0,0)",
123 [UTC_FEB_29_2000-TZ_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
125 addNewTestCase( new Date(2000,1,28,24,0,0,0),
126 "new Date(2000,1,28,24,0,0,0)",
127 [UTC_FEB_29_2000-TZ_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
131 addNewTestCase( new Date(1899,11,31,16,0,0,0),
132 "new Date(1899,11,31,16,0,0,0)",
133 [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
135 addNewTestCase( new Date(1899,11,31,15,59,59,999),
136 "new Date(1899,11,31,15,59,59,999)",
137 [TIME_1900-1,1899,11,31,0,23,59,59,999,1899,11,31,0,15,59,59,999] );
139 addNewTestCase( new Date(1899,11,31,23,59,59,999),
140 "new Date(1899,11,31,23,59,59,999)",
141 [TIME_1900-TZ_ADJUST-1,1900,0,1,1,7,59,59,999,1899,11,31,0,23,59,59,999] );
143 addNewTestCase( new Date(1900,0,1,0,0,0,0),
144 "new Date(1900,0,1,0,0,0,0)",
145 [TIME_1900-TZ_ADJUST,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
147 addNewTestCase( new Date(1900,0,1,0,0,0,1),
148 "new Date(1900,0,1,0,0,0,1)",
149 [TIME_1900-TZ_ADJUST+1,1900,0,1,1,8,0,0,1,1900,0,1,1,0,0,0,1] );
153 var UTC_YEAR_2005 = TIME_2000 + TimeInYear(2000) + TimeInYear(2001) +
154 TimeInYear(2002) + TimeInYear(2003) + TimeInYear(2004);
156 addNewTestCase( new Date(2005,0,1,0,0,0,0),
157 "new Date(2005,0,1,0,0,0,0)",
158 [UTC_YEAR_2005-TZ_ADJUST,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] );
160 addNewTestCase( new Date(2004,11,31,16,0,0,0),
161 "new Date(2004,11,31,16,0,0,0)",
162 [UTC_YEAR_2005,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] );
165 This test case is incorrect. Need to fix the DaylightSavings functions in
166 shell.js for this to work properly.
168 // Daylight Savings test case
170 var DST_START_1998 = UTC( GetSecondSundayInMarch(TimeFromYear(1998)) + 2*msPerHour )
172 addNewTestCase( new Date(1998,3,5,1,59,59,999),
173 "new Date(1998,3,5,1,59,59,999)",
174 [DST_START_1998-1,1998,3,5,0,9,59,59,999,1998,3,5,0,1,59,59,999] );
176 addNewTestCase( new Date(1998,3,5,2,0,0,0),
177 "new Date(1998,3,5,2,0,0,0)",
178 [DST_START_1998,1998,3,5,0,10,0,0,0,1998,3,5,0,3,0,0,0]);
180 var DST_END_1998 = UTC( GetFirstSundayInNovember(TimeFromYear(1998)) + 2*msPerHour );
182 addNewTestCase ( new Date(1998,9,25,1,59,59,999),
183 "new Date(1998,9,25,1,59,59,999)",
184 [DST_END_1998-1,1998,9,25,0,8,59,59,999,1998,9,25,0,1,59,59,999] );
186 addNewTestCase ( new Date(1998,9,25,2,0,0,0),
187 "new Date(1998,9,25,2,0,0,0)",
188 [DST_END_1998,1998,9,25,0,9,0,0,0,1998,9,25,0,1,0,0,0] );
192 function addNewTestCase( DateCase
, DateString
, ResultArray
) {
193 //adjust hard-coded ResultArray for tester's timezone instead of PST
194 adjustResultArray(ResultArray
);
196 var item
= testcases
.length
;
198 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", ResultArray
[TIME
], DateCase
.getTime() );
199 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", ResultArray
[TIME
], DateCase
.valueOf() );
201 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", ResultArray
[UTC_YEAR
], DateCase
.getUTCFullYear() );
202 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", ResultArray
[UTC_MONTH
], DateCase
.getUTCMonth() );
203 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", ResultArray
[UTC_DATE
], DateCase
.getUTCDate() );
204 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDay()", ResultArray
[UTC_DAY
], DateCase
.getUTCDay() );
205 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", ResultArray
[UTC_HOURS
], DateCase
.getUTCHours() );
206 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", ResultArray
[UTC_MINUTES
],DateCase
.getUTCMinutes() );
207 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", ResultArray
[UTC_SECONDS
],DateCase
.getUTCSeconds() );
208 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", ResultArray
[UTC_MS
], DateCase
.getUTCMilliseconds() );
210 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", ResultArray
[YEAR
], DateCase
.getFullYear() );
211 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", ResultArray
[MONTH
], DateCase
.getMonth() );
212 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", ResultArray
[DATE
], DateCase
.getDate() );
213 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDay()", ResultArray
[DAY
], DateCase
.getDay() );
214 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", ResultArray
[HOURS
], DateCase
.getHours() );
215 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", ResultArray
[MINUTES
], DateCase
.getMinutes() );
216 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", ResultArray
[SECONDS
], DateCase
.getSeconds() );
217 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", ResultArray
[MS
], DateCase
.getMilliseconds() );
221 for( tc
= 0; tc
< testcases
.length
; tc
++ ) {
223 testcases
[tc
].passed
= writeTestCaseResult(
224 testcases
[tc
].expect
,
225 testcases
[tc
].actual
,
226 testcases
[tc
].description
+" = " +
227 testcases
[tc
].actual
);