• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.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.
28
29                        The [[Class]] property of the newly constructed object
30                        is set as follows:
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)
37                        7. Call ToNumber(ms)
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),
43                            Result(7)
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))).
47
48
49                        This tests the returned value of a newly constructed
50                        Date object.
51
52    Author:             christine@netscape.com
53    Date:               7 july 1997
54*/
55
56    var SECTION = "15.9.3.1";
57    var VERSION = "ECMA_1";
58    startTest();
59    var TITLE   = "new Date( year, month, date, hours, minutes, seconds, ms )";
60
61    var TIME        = 0;
62    var UTC_YEAR    = 1;
63    var UTC_MONTH   = 2;
64    var UTC_DATE    = 3;
65    var UTC_DAY     = 4;
66    var UTC_HOURS   = 5;
67    var UTC_MINUTES = 6;
68    var UTC_SECONDS = 7;
69    var UTC_MS      = 8;
70
71    var YEAR        = 9;
72    var MONTH       = 10;
73    var DATE        = 11;
74    var DAY         = 12;
75    var HOURS       = 13;
76    var MINUTES     = 14;
77    var SECONDS     = 15;
78    var MS          = 16;
79
80    writeHeaderToLog( SECTION + " "+ TITLE);
81
82    var testcases = new Array();
83
84    getTestCases();
85    test();
86
87function getTestCases( ) {
88    // all the "ResultArrays" below are hard-coded to Pacific Standard Time values -
89    var TZ_ADJUST =  TZ_PST * msPerHour;
90
91    // Dates around 1970
92
93    addNewTestCase( new Date( 1969,11,31,15,59,59,999),
94                    "new Date( 1969,11,31,15,59,59,999)",
95                    [TIME_1970-1,1969,11,31,3,23,59,59,999,1969,11,31,3,15,59,59,999] );
96
97    addNewTestCase( new Date( 1969,11,31,23,59,59,999),
98                    "new Date( 1969,11,31,23,59,59,999)",
99                    [TIME_1970-TZ_ADJUST-1,1970,0,1,4,7,59,59,999,1969,11,31,3,23,59,59,999] );
100
101    addNewTestCase( new Date( 1970,0,1,0,0,0,0),
102                    "new Date( 1970,0,1,0,0,0,0)",
103                    [TIME_1970-TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
104
105    addNewTestCase( new Date( 1969,11,31,16,0,0,0),
106                    "new Date( 1969,11,31,16,0,0,0)",
107                    [TIME_1970,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
108
109    addNewTestCase( new Date(1969,12,1,0,0,0,0),
110                    "new Date(1969,12,1,0,0,0,0)",
111                    [TIME_1970-TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
112
113    addNewTestCase( new Date(1969,11,32,0,0,0,0),
114                    "new Date(1969,11,32,0,0,0,0)",
115                    [TIME_1970-TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
116
117    addNewTestCase( new Date(1969,11,31,24,0,0,0),
118                    "new Date(1969,11,31,24,0,0,0)",
119                    [TIME_1970-TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
120
121    addNewTestCase( new Date(1969,11,31,23,60,0,0),
122                    "new Date(1969,11,31,23,60,0,0)",
123                    [TIME_1970-TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
124
125    addNewTestCase( new Date(1969,11,31,23,59,60,0),
126                    "new Date(1969,11,31,23,59,60,0)",
127                    [TIME_1970-TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
128
129    addNewTestCase( new Date(1969,11,31,23,59,59,1000),
130                    "new Date(1969,11,31,23,59,59,1000)",
131                    [TIME_1970-TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
132
133    // Dates around 2000
134
135    addNewTestCase( new Date( 1999,11,31,15,59,59,999),
136                    "new Date( 1999,11,31,15,59,59,999)",
137                    [TIME_2000-1,1999,11,31,5,23,59,59,999,1999,11,31,5,15,59,59,999] );
138
139    addNewTestCase( new Date( 1999,11,31,16,0,0,0),
140                    "new Date( 1999,11,31,16,0,0,0)",
141                    [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5, 16,0,0,0] );
142
143    addNewTestCase( new Date( 1999,11,31,23,59,59,999),
144                    "new Date( 1999,11,31,23,59,59,999)",
145                    [TIME_2000-TZ_ADJUST-1,2000,0,1,6,7,59,59,999,1999,11,31,5,23,59,59,999] );
146
147    addNewTestCase( new Date( 2000,0,1,0,0,0,0),
148                    "new Date( 2000,0,1,0,0,0,0)",
149                    [TIME_2000-TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
150
151    addNewTestCase( new Date( 2000,0,1,0,0,0,1),
152                    "new Date( 2000,0,1,0,0,0,1)",
153                    [TIME_2000-TZ_ADJUST+1,2000,0,1,6,8,0,0,1,2000,0,1,6,0,0,0,1] );
154
155    // Dates around 29 Feb 2000
156
157    var UTC_FEB_29_2000 = TIME_2000 + ( 30 * msPerDay ) + ( 29 * msPerDay );
158
159    addNewTestCase( new Date(2000,1,28,16,0,0,0),
160                    "new Date(2000,1,28,16,0,0,0)",
161                    [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
162
163    addNewTestCase( new Date(2000,1,29,0,0,0,0),
164                    "new Date(2000,1,29,0,0,0,0)",
165                    [UTC_FEB_29_2000-TZ_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
166
167    addNewTestCase( new Date(2000,1,28,24,0,0,0),
168                    "new Date(2000,1,28,24,0,0,0)",
169                    [UTC_FEB_29_2000-TZ_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
170
171    // Dates around 1900
172
173    addNewTestCase( new Date(1899,11,31,16,0,0,0),
174                    "new Date(1899,11,31,16,0,0,0)",
175                    [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
176
177    addNewTestCase( new Date(1899,11,31,15,59,59,999),
178                    "new Date(1899,11,31,15,59,59,999)",
179                    [TIME_1900-1,1899,11,31,0,23,59,59,999,1899,11,31,0,15,59,59,999] );
180
181    addNewTestCase( new Date(1899,11,31,23,59,59,999),
182                    "new Date(1899,11,31,23,59,59,999)",
183                    [TIME_1900-TZ_ADJUST-1,1900,0,1,1,7,59,59,999,1899,11,31,0,23,59,59,999] );
184
185    addNewTestCase( new Date(1900,0,1,0,0,0,0),
186                    "new Date(1900,0,1,0,0,0,0)",
187                    [TIME_1900-TZ_ADJUST,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
188
189    addNewTestCase( new Date(1900,0,1,0,0,0,1),
190                    "new Date(1900,0,1,0,0,0,1)",
191                    [TIME_1900-TZ_ADJUST+1,1900,0,1,1,8,0,0,1,1900,0,1,1,0,0,0,1] );
192
193    // Dates around 2005
194
195    var UTC_YEAR_2005 = TIME_2000 + TimeInYear(2000) + TimeInYear(2001) +
196    TimeInYear(2002) + TimeInYear(2003) + TimeInYear(2004);
197
198    addNewTestCase( new Date(2005,0,1,0,0,0,0),
199                    "new Date(2005,0,1,0,0,0,0)",
200                    [UTC_YEAR_2005-TZ_ADJUST,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] );
201
202    addNewTestCase( new Date(2004,11,31,16,0,0,0),
203                    "new Date(2004,11,31,16,0,0,0)",
204                    [UTC_YEAR_2005,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] );
205
206/*
207   This test case is incorrect.  Need to fix the DaylightSavings functions in
208   shell.js for this to work properly.
209
210    // Daylight Savings test case
211
212    var DST_START_1998 = UTC( GetSecondSundayInMarch(TimeFromYear(1998)) + 2*msPerHour )
213
214    addNewTestCase( new Date(1998,3,5,1,59,59,999),
215                    "new Date(1998,3,5,1,59,59,999)",
216                    [DST_START_1998-1,1998,3,5,0,9,59,59,999,1998,3,5,0,1,59,59,999] );
217
218    addNewTestCase( new Date(1998,3,5,2,0,0,0),
219                    "new Date(1998,3,5,2,0,0,0)",
220                    [DST_START_1998,1998,3,5,0,10,0,0,0,1998,3,5,0,3,0,0,0]);
221
222    var DST_END_1998 = UTC( GetFirstSundayInNovember(TimeFromYear(1998)) + 2*msPerHour );
223
224    addNewTestCase ( new Date(1998,9,25,1,59,59,999),
225                    "new Date(1998,9,25,1,59,59,999)",
226                    [DST_END_1998-1,1998,9,25,0,8,59,59,999,1998,9,25,0,1,59,59,999] );
227
228    addNewTestCase ( new Date(1998,9,25,2,0,0,0),
229                    "new Date(1998,9,25,2,0,0,0)",
230                    [DST_END_1998,1998,9,25,0,9,0,0,0,1998,9,25,0,1,0,0,0] );
231*/
232}
233
234function addNewTestCase( DateCase, DateString, ResultArray ) {
235    //adjust hard-coded ResultArray for tester's timezone instead of PST
236    adjustResultArray(ResultArray);
237
238    var item = testcases.length;
239
240    testcases[item++] = new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME],       DateCase.getTime() );
241    testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME],       DateCase.valueOf() );
242
243    testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      ResultArray[UTC_YEAR],  DateCase.getUTCFullYear() );
244    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         ResultArray[UTC_MONTH],  DateCase.getUTCMonth() );
245    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          ResultArray[UTC_DATE],   DateCase.getUTCDate() );
246    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           ResultArray[UTC_DAY],    DateCase.getUTCDay() );
247    testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         ResultArray[UTC_HOURS],  DateCase.getUTCHours() );
248    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
249    testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
250    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  ResultArray[UTC_MS],     DateCase.getUTCMilliseconds() );
251
252    testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         ResultArray[YEAR],       DateCase.getFullYear() );
253    testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            ResultArray[MONTH],      DateCase.getMonth() );
254    testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             ResultArray[DATE],       DateCase.getDate() );
255    testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              ResultArray[DAY],        DateCase.getDay() );
256    testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            ResultArray[HOURS],      DateCase.getHours() );
257    testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          ResultArray[MINUTES],    DateCase.getMinutes() );
258    testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          ResultArray[SECONDS],    DateCase.getSeconds() );
259    testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     ResultArray[MS],         DateCase.getMilliseconds() );
260}
261
262
263function test() {
264    for( tc = 0; tc < testcases.length; tc++ ) {
265
266        testcases[tc].passed = writeTestCaseResult(
267                                testcases[tc].expect,
268                                testcases[tc].actual,
269                                testcases[tc].description +" = " +
270                                testcases[tc].actual );
271    }
272    stopTest();
273    return testcases;
274}
275