]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.4.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.4.2.js
24 ECMA Section: 15.9.4.2 Date.parse()
25 Description: The parse() function applies the to ToString() operator
26 to its argument and interprets the resulting string as
27 a date. It returns a number, the UTC time value
28 corresponding to the date.
30 The string may be interpreted as a local time, a UTC
31 time, or a time in some other time zone, depending on
32 the contents of the string.
34 (need to test strings containing stuff with the time
35 zone specified, and verify that parse() returns the
38 so for any Date object x, all of these things should
41 value tested in function:
42 x.valueOf() test_value()
43 Date.parse(x.toString()) test_tostring()
44 Date.parse(x.toGMTString()) test_togmt()
46 Date.parse(x.toLocaleString()) is not required to
47 produce the same number value as the preceeding three
48 expressions. in general the value produced by
49 Date.parse is implementation dependent when given any
50 string value that could not be produced in that
51 implementation by the toString or toGMTString method.
53 value tested in function:
54 Date.parse( x.toLocaleString()) test_tolocale()
56 Author: christine@netscape.com
61 var VERSION
= "ECMA_1";
63 var SECTION
= "15.9.4.2";
64 var TITLE
= "Date.parse()";
84 var TYPEOF
= "object";
86 // for TCMS, the testcases array must be global.
87 writeHeaderToLog("15.9.4.2 Date.parse()" );
89 testcases
= new Array();
92 // all tests must call a function that returns an array of TestCase objects.
95 function getTestCases() {
99 addNewTestCase( new Date(0),
101 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
103 addNewTestCase( new Date(-1),
105 [-1,1969,11,31,3,23,59,59,999,1969,11,31,3,15,59,59,999] );
106 addNewTestCase( new Date(28799999),
107 "new Date(28799999)",
108 [28799999,1970,0,1,4,7,59,59,999,1969,11,31,3,23,59,59,999] );
109 addNewTestCase( new Date(28800000),
110 "new Date(28800000)",
111 [28800000,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
115 addNewTestCase( new Date(946684799999),
116 "new Date(946684799999)",
117 [946684799999,1999,11,31,5,23,59,59,999,1999,11,31,5,15,59,59,999] );
118 addNewTestCase( new Date(946713599999),
119 "new Date(946713599999)",
120 [946713599999,2000,0,1,6,7,59,59,999,1999,11,31,5,23,59,59,999] );
121 addNewTestCase( new Date(946684800000),
122 "new Date(946684800000)",
123 [946684800000,2000,0,1,6,0,0,0,0,1999,11,31,5, 16,0,0,0] );
124 addNewTestCase( new Date(946713600000),
125 "new Date(946713600000)",
126 [946713600000,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
130 addNewTestCase( new Date(-2208988800000),
131 "new Date(-2208988800000)",
132 [-2208988800000,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
134 addNewTestCase( new Date(-2208988800001),
135 "new Date(-2208988800001)",
136 [-2208988800001,1899,11,31,0,23,59,59,999,1899,11,31,0,15,59,59,999] );
138 addNewTestCase( new Date(-2208960000001),
139 "new Date(-2208960000001)",
140 [-2208960000001,1900,0,1,1,7,59,59,0,1899,11,31,0,23,59,59,999] );
141 addNewTestCase( new Date(-2208960000000),
142 "new Date(-2208960000000)",
143 [-2208960000000,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
144 addNewTestCase( new Date(-2208959999999),
145 "new Date(-2208959999999)",
146 [-2208959999999,1900,0,1,1,8,0,0,1,1900,0,1,1,0,0,0,1] );
148 // Dates around Feb 29, 2000
150 var UTC_FEB_29_2000
= TIME_2000
+ 31*msPerDay
+ 28*msPerDay
;
151 var PST_FEB_29_2000
= UTC_FEB_29_2000
+ 8*msPerHour
;
152 addNewTestCase( new Date(UTC_FEB_29_2000
),
153 "new Date(" + UTC_FEB_29_2000
+")",
154 [UTC_FEB_29_2000
,2000,0,1,6,0,0,0,0,1999,11,31,5,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,0,1,6,8.0,0,0,2000,0,1,6,0,0,0,0]);
159 // Dates around Jan 1 2005
161 var UTC_JAN_1_2005
= TIME_2000
+ TimeInYear(2000) + TimeInYear(2001) +
162 TimeInYear(2002) + TimeInYear(2003) + TimeInYear(2004);
163 var PST_JAN_1_2005
= UTC_JAN_1_2005
+ 8*msPerHour
;
165 addNewTestCase( new Date(UTC_JAN_1_2005
),
166 "new Date("+ UTC_JAN_1_2005
+")",
167 [UTC_JAN_1_2005
,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] );
168 addNewTestCase( new Date(PST_JAN_1_2005
),
169 "new Date("+ PST_JAN_1_2005
+")",
170 [PST_JAN_1_2005
,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] );
173 function addNewTestCase( DateCase
, DateString
, ResultArray
) {
176 item
= testcases
.length
;
178 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", ResultArray
[TIME
], DateCase
.getTime() );
179 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", ResultArray
[TIME
], DateCase
.valueOf() );
180 testcases
[item
++] = new TestCase( SECTION
, "Date.parse(" + DateCase
.toString() +")", Math
.floor(ResultArray
[TIME
]/1000)*1000, Date
.parse(DateCase
.toString()) );
181 testcases
[item
++] = new TestCase( SECTION
, "Date.parse(" + DateCase
.toGMTString() +")", Math
.floor(ResultArray
[TIME
]/1000)*1000, Date
.parse(DateCase
.toGMTString()) );
183 testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()", ResultArray[UTC_YEAR], DateCase.getUTCFullYear() );
184 testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()", ResultArray[UTC_MONTH], DateCase.getUTCMonth() );
185 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()", ResultArray[UTC_DATE], DateCase.getUTCDate() );
186 testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()", ResultArray[UTC_DAY], DateCase.getUTCDay() z inutes() );
187 testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()", ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
188 // testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()", ResultArray[UTC_MS], DateCase.getUTCMilliseconds() );
190 testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()", ResultArray[YEAR], DateCase.getFullYear() );
191 testcases[item++] = new TestCase( SECTION, DateString+".getMonth()", ResultArray[MONTH], DateCase.getMonth() );
192 testcases[item++] = new TestCase( SECTION, DateString+".getDate()", ResultArray[DATE], DateCase.getDate() );
193 testcases[item++] = new TestCase( SECTION, DateString+".getDay()", ResultArray[DAY], DateCase.getDay() );
194 testcases[item++] = new TestCase( SECTION, DateString+".getHours()", ResultArray[HOURS], DateCase.getHours() );
195 testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()", ResultArray[MINUTES], DateCase.getMinutes() );
196 testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()", ResultArray[SECONDS], DateCase.getSeconds() );
197 // testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()", ResultArray[MS], DateCase.getMilliseconds() );
201 for( tc
= 0; tc
< testcases
.length
; tc
++ ) {
203 testcases
[tc
].passed
= writeTestCaseResult(
204 testcases
[tc
].expect
,
205 testcases
[tc
].actual
,
206 testcases
[tc
].description
+" = " +
207 testcases
[tc
].actual
);
211 // all tests must return an array of TestCase objects
212 return ( testcases
);