Debian Codegraph @

rhino/testsrc/tests/ecma/Date/15.9.3.1-1.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = '15.9.3.1-1.js';
7
8 /**
9 File Name: 15.9.3.1.js
10 ECMA Section: 15.9.3.1 new Date (year, month, date, hours, minutes, seconds, ms)
11 Description: The [[Prototype]] property of the newly constructed
12 object is set to the original Date prototype object,
13 the one that is the initial value of Date.prototype.
14
15 The [[Class]] property of the newly constructed object
16 is set as follows:
17 1. Call ToNumber(year)
18 2. Call ToNumber(month)
19 3. Call ToNumber(date)
20 4. Call ToNumber(hours)
21 5. Call ToNumber(minutes)
22 6. Call ToNumber(seconds)
23 7. Call ToNumber(ms)
24 8. If Result(1) is NaN and 0 <= ToInteger(Result(1)) <=
25 99, Result(8) is 1900+ToInteger(Result(1)); otherwise,
26 Result(8) is Result(1)
27 9. Compute MakeDay(Result(8), Result(2), Result(3)
28 10. Compute MakeTime(Result(4), Result(5), Result(6),
29 Result(7)
30 11. Compute MakeDate(Result(9), Result(10))
31 12. Set the [[Value]] property of the newly constructed
32 object to TimeClip(UTC(Result(11))).
33
34
35 This tests the returned value of a newly constructed
36 Date object.
37
38 Author: [email protected]
39 Date: 7 july 1997
40 */
41
42 var SECTION = "15.9.3.1";
43 var VERSION = "ECMA_1";
44 startTest();
45 var TITLE = "new Date( year, month, date, hours, minutes, seconds, ms )";
46
47 var TIME = 0;
48 var UTC_YEAR = 1;
49 var UTC_MONTH = 2;
50 var UTC_DATE = 3;
51 var UTC_DAY = 4;
52 var UTC_HOURS = 5;
53 var UTC_MINUTES = 6;
54 var UTC_SECONDS = 7;
55 var UTC_MS = 8;
56
57 var YEAR = 9;
58 var MONTH = 10;
59 var DATE = 11;
60 var DAY = 12;
61 var HOURS = 13;
62 var MINUTES = 14;
63 var SECONDS = 15;
64 var MS = 16;
65
66 writeHeaderToLog( SECTION + " "+ TITLE);
67
68 // Dates around 1970
69
70 addNewTestCase( new Date( 1969,11,31,15,59,59,999),
71 "new Date( 1969,11,31,15,59,59,999)",
72 [TIME_1970-1,1969,11,31,3,23,59,59,999,1969,11,31,3,15,59,59,999] );
73
74 addNewTestCase( new Date( 1969,11,31,23,59,59,999),
75 "new Date( 1969,11,31,23,59,59,999)",
76 [TIME_1970-PST_ADJUST-1,1970,0,1,4,7,59,59,999,1969,11,31,3,23,59,59,999] );
77
78 addNewTestCase( new Date( 1970,0,1,0,0,0,0),
79 "new Date( 1970,0,1,0,0,0,0)",
80 [TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
81
82 addNewTestCase( new Date( 1969,11,31,16,0,0,0),
83 "new Date( 1969,11,31,16,0,0,0)",
84 [TIME_1970,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
85
86 addNewTestCase( new Date(1969,12,1,0,0,0,0),
87 "new Date(1969,12,1,0,0,0,0)",
88 [TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
89
90 addNewTestCase( new Date(1969,11,32,0,0,0,0),
91 "new Date(1969,11,32,0,0,0,0)",
92 [TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
93
94 addNewTestCase( new Date(1969,11,31,24,0,0,0),
95 "new Date(1969,11,31,24,0,0,0)",
96 [TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
97
98 addNewTestCase( new Date(1969,11,31,23,60,0,0),
99 "new Date(1969,11,31,23,60,0,0)",
100 [TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
101
102 addNewTestCase( new Date(1969,11,31,23,59,60,0),
103 "new Date(1969,11,31,23,59,60,0)",
104 [TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
105
106 addNewTestCase( new Date(1969,11,31,23,59,59,1000),
107 "new Date(1969,11,31,23,59,59,1000)",
108 [TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
109
110 // Dates around 2000
111
112 addNewTestCase( new Date( 1999,11,31,15,59,59,999),
113 "new Date( 1999,11,31,15,59,59,999)",
114 [TIME_2000-1,1999,11,31,5,23,59,59,999,1999,11,31,5,15,59,59,999] );
115
116 addNewTestCase( new Date( 1999,11,31,16,0,0,0),
117 "new Date( 1999,11,31,16,0,0,0)",
118 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5, 16,0,0,0] );
119
120 addNewTestCase( new Date( 1999,11,31,23,59,59,999),
121 "new Date( 1999,11,31,23,59,59,999)",
122 [TIME_2000-PST_ADJUST-1,2000,0,1,6,7,59,59,999,1999,11,31,5,23,59,59,999] );
123
124 addNewTestCase( new Date( 2000,0,1,0,0,0,0),
125 "new Date( 2000,0,1,0,0,0,0)",
126 [TIME_2000-PST_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
127
128 addNewTestCase( new Date( 2000,0,1,0,0,0,1),
129 "new Date( 2000,0,1,0,0,0,1)",
130 [TIME_2000-PST_ADJUST+1,2000,0,1,6,8,0,0,1,2000,0,1,6,0,0,0,1] );
131
132 // Dates around 29 Feb 2000
133
134 addNewTestCase( new Date(2000,1,28,16,0,0,0),
135 "new Date(2000,1,28,16,0,0,0)",
136 [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
137
138 addNewTestCase( new Date(2000,1,29,0,0,0,0),
139 "new Date(2000,1,29,0,0,0,0)",
140 [UTC_FEB_29_2000-PST_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
141
142 addNewTestCase( new Date(2000,1,28,24,0,0,0),
143 "new Date(2000,1,28,24,0,0,0)",
144 [UTC_FEB_29_2000-PST_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
145
146 // Dates around 1900
147
148 addNewTestCase( new Date(1899,11,31,16,0,0,0),
149 "new Date(1899,11,31,16,0,0,0)",
150 [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
151
152 addNewTestCase( new Date(1899,11,31,15,59,59,999),
153 "new Date(1899,11,31,15,59,59,999)",
154 [TIME_1900-1,1899,11,31,0,23,59,59,999,1899,11,31,0,15,59,59,999] );
155
156 addNewTestCase( new Date(1899,11,31,23,59,59,999),
157 "new Date(1899,11,31,23,59,59,999)",
158 [TIME_1900-PST_ADJUST-1,1900,0,1,1,7,59,59,999,1899,11,31,0,23,59,59,999] );
159
160 addNewTestCase( new Date(1900,0,1,0,0,0,0),
161 "new Date(1900,0,1,0,0,0,0)",
162 [TIME_1900-PST_ADJUST,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
163
164 addNewTestCase( new Date(1900,0,1,0,0,0,1),
165 "new Date(1900,0,1,0,0,0,1)",
166 [TIME_1900-PST_ADJUST+1,1900,0,1,1,8,0,0,1,1900,0,1,1,0,0,0,1] );
167
168 // Dates around 2005
169
170 addNewTestCase( new Date(2005,0,1,0,0,0,0),
171 "new Date(2005,0,1,0,0,0,0)",
172 [UTC_JAN_1_2005-PST_ADJUST,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] );
173
174 addNewTestCase( new Date(2004,11,31,16,0,0,0),
175 "new Date(2004,11,31,16,0,0,0)",
176 [UTC_JAN_1_2005,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] );
177
178 test();
179
180
181 function addNewTestCase( DateCase, DateString, ResultArray ) {
182 //adjust hard-coded ResultArray for tester's timezone instead of PST
183 adjustResultArray(ResultArray);
184
185 new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME], DateCase.getTime() );
186 new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME], DateCase.valueOf() );
187
188 new TestCase( SECTION, DateString+".getUTCFullYear()", ResultArray[UTC_YEAR], DateCase.getUTCFullYear() );
189 new TestCase( SECTION, DateString+".getUTCMonth()", ResultArray[UTC_MONTH], DateCase.getUTCMonth() );
190 new TestCase( SECTION, DateString+".getUTCDate()", ResultArray[UTC_DATE], DateCase.getUTCDate() );
191 new TestCase( SECTION, DateString+".getUTCDay()", ResultArray[UTC_DAY], DateCase.getUTCDay() );
192 new TestCase( SECTION, DateString+".getUTCHours()", ResultArray[UTC_HOURS], DateCase.getUTCHours() );
193 new TestCase( SECTION, DateString+".getUTCMinutes()", ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
194 new TestCase( SECTION, DateString+".getUTCSeconds()", ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
195 new TestCase( SECTION, DateString+".getUTCMilliseconds()", ResultArray[UTC_MS], DateCase.getUTCMilliseconds() );
196
197 new TestCase( SECTION, DateString+".getFullYear()", ResultArray[YEAR], DateCase.getFullYear() );
198 new TestCase( SECTION, DateString+".getMonth()", ResultArray[MONTH], DateCase.getMonth() );
199 new TestCase( SECTION, DateString+".getDate()", ResultArray[DATE], DateCase.getDate() );
200 new TestCase( SECTION, DateString+".getDay()", ResultArray[DAY], DateCase.getDay() );
201 new TestCase( SECTION, DateString+".getHours()", ResultArray[HOURS], DateCase.getHours() );
202 new TestCase( SECTION, DateString+".getMinutes()", ResultArray[MINUTES], DateCase.getMinutes() );
203 new TestCase( SECTION, DateString+".getSeconds()", ResultArray[SECONDS], DateCase.getSeconds() );
204 new TestCase( SECTION, DateString+".getMilliseconds()", ResultArray[MS], DateCase.getMilliseconds() );
205 }
206