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/
5 *
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.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
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
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
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.
29
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.
33
34                        (need to test strings containing stuff with the time
35                        zone specified, and verify that parse() returns the
36                        correct GMT time)
37
38                        so for any Date object x, all of these things should
39                        be equal:
40
41                        value                       tested in function:
42                        x.valueOf()                 test_value()
43                        Date.parse(x.toString())    test_tostring()
44                        Date.parse(x.toGMTString()) test_togmt()
45
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.
52
53                        value                           tested in function:
54                        Date.parse( x.toLocaleString()) test_tolocale()
55
56    Author:             christine@netscape.com
57    Date:               10 july 1997
58
59*/
60
61    var VERSION = "ECMA_1";
62    startTest();
63    var SECTION = "15.9.4.2";
64    var TITLE   = "Date.parse()";
65
66    var TIME        = 0;
67    var UTC_YEAR    = 1;
68    var UTC_MONTH   = 2;
69    var UTC_DATE    = 3;
70    var UTC_DAY     = 4;
71    var UTC_HOURS   = 5;
72    var UTC_MINUTES = 6;
73    var UTC_SECONDS = 7;
74    var UTC_MS      = 8;
75
76    var YEAR        = 9;
77    var MONTH       = 10;
78    var DATE        = 11;
79    var DAY         = 12;
80    var HOURS       = 13;
81    var MINUTES     = 14;
82    var SECONDS     = 15;
83    var MS          = 16;
84    var TYPEOF  = "object";
85
86//  for TCMS, the testcases array must be global.
87    writeHeaderToLog("15.9.4.2 Date.parse()" );
88    var tc= 0;
89    testcases = new Array();
90    getTestCases();
91
92//  all tests must call a function that returns an array of TestCase objects.
93    test();
94
95function getTestCases() {
96
97    // Dates around 1970
98
99    addNewTestCase( new Date(0),
100                    "new Date(0)",
101                    [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
102
103    addNewTestCase( new Date(-1),
104                    "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] );
112
113    // Dates around 2000
114
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] );
127
128    // Dates around 1900
129
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] );
133
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] );
137
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] );
147
148    // Dates around Feb 29, 2000
149
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]);
158
159    // Dates around Jan 1 2005
160
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;
164
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] );
171
172}
173function addNewTestCase( DateCase, DateString, ResultArray ) {
174    DateCase = DateCase;
175
176    item = testcases.length;
177
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()) );
182/*
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() );
189
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() );
198*/
199}
200function test() {
201    for( tc = 0; tc < testcases.length; tc++ ) {
202
203        testcases[tc].passed = writeTestCaseResult(
204                                testcases[tc].expect,
205                                testcases[tc].actual,
206                                testcases[tc].description +" = " +
207                                testcases[tc].actual );
208    }
209        stopTest();
210
211    //  all tests must return an array of TestCase objects
212        return ( testcases );
213}
214