]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
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.2.1.js | |
24 | ECMA Section: 15.9.2.1 Date constructor used as a function | |
25 | Date( year, month, date, hours, minutes, seconds, ms ) | |
26 | Description: The arguments are accepted, but are completely ignored. | |
27 | A string is created and returned as if by the | |
28 | expression (new Date()).toString(). | |
29 | ||
30 | Author: christine@netscape.com | |
31 | Date: 28 october 1997 | |
32 | ||
33 | */ | |
34 | var VERSION = "ECMA_1"; | |
35 | startTest(); | |
36 | var SECTION = "15.9.2.1"; | |
37 | var TITLE = "Date Constructor used as a function"; | |
38 | var TYPEOF = "string"; | |
b37bf2e1 A |
39 | |
40 | writeHeaderToLog("15.9.2.1 The Date Constructor Called as a Function: " + | |
41 | "Date( year, month, date, hours, minutes, seconds, ms )" ); | |
42 | var tc= 0; | |
43 | var testcases = getTestCases(); | |
44 | ||
45 | // all tests must call a function that returns an array of TestCase objects. | |
46 | test(); | |
47 | ||
48 | function getTestCases() { | |
49 | var array = new Array(); | |
50 | var item = 0; | |
51 | ||
52 | var TODAY = new Date(); | |
53 | ||
ed1e77d3 A |
54 | // allow up to 1 second difference due to possibility |
55 | // the date may change by 1 second in between calls to Date | |
56 | ||
57 | var d1; | |
58 | var d2; | |
59 | ||
b37bf2e1 A |
60 | // Dates around 1970 |
61 | ||
ed1e77d3 A |
62 | d1 = new Date(); |
63 | d2 = Date.parse(Date(1970,0,1,0,0,0,0)); | |
64 | array[item++] = new TestCase(SECTION, "Date(1970,0,1,0,0,0,0)", true, d2 - d1 <= 1000); | |
65 | ||
66 | d1 = new Date(); | |
67 | d2 = Date.parse(Date(1969,11,31,15,59,59,999)); | |
68 | array[item++] = new TestCase(SECTION, "Date(1969,11,31,15,59,59,999)", true, d2 - d1 <= 1000); | |
69 | ||
70 | d1 = new Date(); | |
71 | d2 = Date.parse(Date(1969,11,31,16,0,0,0)); | |
72 | array[item++] = new TestCase(SECTION, "Date(1969,11,31,16,0,0,0)", true, d2 - d1 <= 1000); | |
73 | ||
74 | d1 = new Date(); | |
75 | d2 = Date.parse(Date(1969,11,31,16,0,0,1)); | |
76 | array[item++] = new TestCase(SECTION, "Date(1969,11,31,16,0,0,1)", true, d2 - d1 <= 1000); | |
b37bf2e1 A |
77 | |
78 | // Dates around 2000 | |
ed1e77d3 A |
79 | d1 = new Date(); |
80 | d2 = Date.parse(Date(1999,11,15,59,59,999)); | |
81 | array[item++] = new TestCase(SECTION, "Date(1999,11,15,59,59,999)", true, d2 - d1 <= 1000); | |
82 | ||
83 | d1 = new Date(); | |
84 | d2 = Date.parse(Date(1999,11,16,0,0,0,0)); | |
85 | array[item++] = new TestCase(SECTION, "Date(1999,11,16,0,0,0,0)", true, d2 - d1 <= 1000); | |
86 | ||
87 | d1 = new Date(); | |
88 | d2 = Date.parse(Date(1999,11,31,23,59,59,999)); | |
89 | array[item++] = new TestCase(SECTION, "Date(1999,11,31,23,59,59,999)", true, d2 - d1 <= 1000); | |
90 | ||
91 | d1 = new Date(); | |
92 | d2 = Date.parse(Date(2000,0,0,0,0,0,0)); | |
93 | array[item++] = new TestCase(SECTION, "Date(2000,0,1,0,0,0,0)", true, d2 - d1 <= 1000); | |
94 | ||
95 | d1 = new Date(); | |
96 | d2 = Date.parse(Date(2000,0,0,0,0,0,1)); | |
97 | array[item++] = new TestCase(SECTION, "Date(2000,0,1,0,0,0,1)", true, d2 - d1 <= 1000); | |
b37bf2e1 A |
98 | |
99 | // Dates around 1900 | |
100 | ||
ed1e77d3 A |
101 | d1 = new Date(); |
102 | d2 = Date.parse(Date(1899,11,31,23,59,59,999)); | |
103 | array[item++] = new TestCase(SECTION, "Date(1899,11,31,23,59,59,999)", true, d2 - d1 <= 1000); | |
104 | ||
105 | d1 = new Date(); | |
106 | d2 = Date.parse(Date(1900,0,1,0,0,0,0)); | |
107 | array[item++] = new TestCase(SECTION, "Date(1900,0,1,0,0,0,0)", true, d2 - d1 <= 1000); | |
108 | ||
109 | d1 = new Date(); | |
110 | d2 = Date.parse(Date(1900,0,1,0,0,0,1)); | |
111 | array[item++] = new TestCase(SECTION, "Date(1900,0,1,0,0,0,1)", true, d2 - d1 <= 1000); | |
112 | ||
113 | d1 = new Date(); | |
114 | d2 = Date.parse(Date(1899,11,31,16,0,0,0,0)); | |
115 | array[item++] = new TestCase(SECTION, "Date(1899,11,31,16,0,0,0,0)", true, d2 - d1 <= 1000); | |
b37bf2e1 A |
116 | |
117 | // Dates around feb 29, 2000 | |
118 | ||
ed1e77d3 A |
119 | d1 = new Date(); |
120 | d2 = Date.parse(Date(2000,1,29,0,0,0,0)); | |
121 | array[item++] = new TestCase(SECTION, "Date(2000,1,29,0,0,0,0)", true, d2 - d1 <= 1000); | |
122 | ||
123 | d1 = new Date(); | |
124 | d2 = Date.parse(Date(2000,1,28,23,59,59,999)); | |
125 | array[item++] = new TestCase(SECTION, "Date(2000,1,28,23,59,59,999)", true, d2 - d1 <= 1000); | |
126 | ||
127 | d1 = new Date(); | |
128 | d2 = Date.parse(Date(2000,1,27,16,0,0,0)); | |
129 | array[item++] = new TestCase(SECTION, "Date(2000,1,27,16,0,0,0)", true, d2 - d1 <= 1000); | |
b37bf2e1 A |
130 | |
131 | // Dates around jan 1, 2005 | |
ed1e77d3 A |
132 | d1 = new Date(); |
133 | d2 = Date.parse(Date(2004,11,31,23,59,59,999)); | |
134 | array[item++] = new TestCase(SECTION, "Date(2004,11,31,23,59,59,999)", true, d2 - d1 <= 1000); | |
135 | ||
136 | d1 = new Date(); | |
137 | d2 = Date.parse(Date(2005,0,1,0,0,0,0)); | |
138 | array[item++] = new TestCase(SECTION, "Date(2005,0,1,0,0,0,0)", true, d2 - d1 <= 1000); | |
139 | ||
140 | d1 = new Date(); | |
141 | d2 = Date.parse(Date(2005,0,1,0,0,0,1)); | |
142 | array[item++] = new TestCase(SECTION, "Date(2005,0,1,0,0,0,1)", true, d2 - d1 <= 1000); | |
143 | ||
144 | d1 = new Date(); | |
145 | d2 = Date.parse(Date(2004,11,31,16,0,0,0,0)); | |
146 | array[item++] = new TestCase(SECTION, "Date(2004,11,31,16,0,0,0,0)", true, d2 - d1 <= 1000); | |
b37bf2e1 A |
147 | |
148 | // Dates around jan 1, 2032 | |
ed1e77d3 A |
149 | d1 = new Date(); |
150 | d2 = Date.parse(Date(2031,11,31,23,59,59,999)); | |
151 | array[item++] = new TestCase(SECTION, "Date(2031,11,31,23,59,59,999)", true, d2 - d1 <= 1000); | |
152 | ||
153 | d1 = new Date(); | |
154 | d2 = Date.parse(Date(2032,0,1,0,0,0,0)); | |
155 | array[item++] = new TestCase(SECTION, "Date(2032,0,1,0,0,0,0)", true, d2 - d1 <= 1000); | |
156 | ||
157 | d1 = new Date(); | |
158 | d2 = Date.parse(Date(2032,0,1,0,0,0,1)); | |
159 | array[item++] = new TestCase(SECTION, "Date(2032,0,1,0,0,0,1)", true, d2 - d1 <= 1000); | |
160 | ||
161 | d1 = new Date(); | |
162 | d2 = Date.parse(Date(2031,11,31,16,0,0,0,0)); | |
163 | array[item++] = new TestCase(SECTION, "Date(2031,11,31,16,0,0,0,0)", true, d2 - d1 <= 1000); | |
b37bf2e1 A |
164 | |
165 | return ( array ); | |
166 | } | |
167 | function test() { | |
168 | for ( tc=0; tc < testcases.length; tc++ ) { | |
169 | testcases[tc].passed = writeTestCaseResult( | |
170 | testcases[tc].expect, | |
171 | testcases[tc].actual, | |
172 | testcases[tc].description +" = "+ | |
173 | testcases[tc].actual ); | |
174 | ||
175 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
176 | } | |
177 | stopTest(); | |
178 | return ( testcases ); | |
179 | } |