* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma / Date / 15.9.3.1-3.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
18  * The Initial Developer of the Original Code is
19  * Netscape Communications Corporation.
20  * Portions created by the Initial Developer are Copyright (C) 1998
21  * the Initial Developer. All Rights Reserved.
22  *
23  * Contributor(s):
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /**
40    File Name:          15.9.3.1.js
41    ECMA Section:       15.9.3.1 new Date (year, month, date, hours, minutes, seconds, ms)
42    Description:        The [[Prototype]] property of the newly constructed
43    object is set to the original Date prototype object,
44    the one that is the initial value of Date.prototype.
45
46    The [[Class]] property of the newly constructed object
47    is set as follows:
48    1. Call ToNumber(year)
49    2. Call ToNumber(month)
50    3. Call ToNumber(date)
51    4. Call ToNumber(hours)
52    5. Call ToNumber(minutes)
53    6. Call ToNumber(seconds)
54    7. Call ToNumber(ms)
55    8.  If Result(1) is NaN and 0 <= ToInteger(Result(1)) <=
56    99, Result(8) is 1900+ToInteger(Result(1)); otherwise,
57    Result(8) is Result(1)
58    9.  Compute MakeDay(Result(8), Result(2), Result(3)
59    10. Compute MakeTime(Result(4), Result(5), Result(6),
60    Result(7)
61    11. Compute MakeDate(Result(9), Result(10))
62    12. Set the [[Value]] property of the newly constructed
63    object to TimeClip(UTC(Result(11))).
64
65
66    This tests the returned value of a newly constructed
67    Date object.
68
69    Author:             christine@netscape.com
70    Date:               7 july 1997
71 */
72
73 var SECTION = "15.9.3.1";
74 var VERSION = "ECMA_1";
75 startTest();
76 var TITLE   = "new Date( year, month, date, hours, minutes, seconds, ms )";
77
78 var TIME        = 0;
79 var UTC_YEAR    = 1;
80 var UTC_MONTH   = 2;
81 var UTC_DATE    = 3;
82 var UTC_DAY     = 4;
83 var UTC_HOURS   = 5;
84 var UTC_MINUTES = 6;
85 var UTC_SECONDS = 7;
86 var UTC_MS      = 8;
87
88 var YEAR        = 9;
89 var MONTH       = 10;
90 var DATE        = 11;
91 var DAY         = 12;
92 var HOURS       = 13;
93 var MINUTES     = 14;
94 var SECONDS     = 15;
95 var MS          = 16;
96
97 writeHeaderToLog( SECTION + " "+ TITLE);
98
99 // all the "ResultArrays" below are hard-coded to Pacific Standard Time values -
100 var TZ_ADJUST =  TZ_PST * msPerHour;
101
102 // Dates around 29 Feb 2000
103
104 var UTC_FEB_29_2000 = TIME_2000 + ( 30 * msPerDay ) + ( 29 * msPerDay );
105
106 addNewTestCase( new Date(2000,1,28,16,0,0,0),
107                 "new Date(2000,1,28,16,0,0,0)",
108                 [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
109
110 addNewTestCase( new Date(2000,1,29,0,0,0,0),
111                 "new Date(2000,1,29,0,0,0,0)",
112                 [UTC_FEB_29_2000-TZ_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
113
114 addNewTestCase( new Date(2000,1,28,24,0,0,0),
115                 "new Date(2000,1,28,24,0,0,0)",
116                 [UTC_FEB_29_2000-TZ_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
117 /*
118 // Dates around 1900
119
120 addNewTestCase( new Date(1899,11,31,16,0,0,0),
121 "new Date(1899,11,31,16,0,0,0)",
122 [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
123
124 addNewTestCase( new Date(1899,11,31,15,59,59,999),
125 "new Date(1899,11,31,15,59,59,999)",
126 [TIME_1900-1,1899,11,31,0,23,59,59,999,1899,11,31,0,15,59,59,999] );
127
128 addNewTestCase( new Date(1899,11,31,23,59,59,999),
129 "new Date(1899,11,31,23,59,59,999)",
130 [TIME_1900-TZ_ADJUST-1,1900,0,1,1,7,59,59,999,1899,11,31,0,23,59,59,999] );
131
132 addNewTestCase( new Date(1900,0,1,0,0,0,0),
133 "new Date(1900,0,1,0,0,0,0)",
134 [TIME_1900-TZ_ADJUST,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
135
136 addNewTestCase( new Date(1900,0,1,0,0,0,1),
137 "new Date(1900,0,1,0,0,0,1)",
138 [TIME_1900-TZ_ADJUST+1,1900,0,1,1,8,0,0,1,1900,0,1,1,0,0,0,1] );
139
140 // Dates around 2005
141
142 var UTC_YEAR_2005 = TIME_2000 + TimeInYear(2000) + TimeInYear(2001) +
143 TimeInYear(2002) + TimeInYear(2003) + TimeInYear(2004);
144
145 addNewTestCase( new Date(2005,0,1,0,0,0,0),
146 "new Date(2005,0,1,0,0,0,0)",
147 [UTC_YEAR_2005-TZ_ADJUST,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] );
148
149 addNewTestCase( new Date(2004,11,31,16,0,0,0),
150 "new Date(2004,11,31,16,0,0,0)",
151 [UTC_YEAR_2005,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] );
152 */
153 /*
154   This test case is incorrect.  Need to fix the DaylightSavings functions in
155   shell.js for this to work properly.
156
157   // Daylight Savings test case
158
159   var DST_START_1998 = UTC( GetFirstSundayInApril(TimeFromYear(1998)) + 2*msPerHour )
160
161   addNewTestCase( new Date(1998,3,5,1,59,59,999),
162   "new Date(1998,3,5,1,59,59,999)",
163   [DST_START_1998-1,1998,3,5,0,9,59,59,999,1998,3,5,0,1,59,59,999] );
164
165   addNewTestCase( new Date(1998,3,5,2,0,0,0),
166   "new Date(1998,3,5,2,0,0,0)",
167   [DST_START_1998,1998,3,5,0,10,0,0,0,1998,3,5,0,3,0,0,0]);
168
169   var DST_END_1998 = UTC( GetLastSundayInOctober(TimeFromYear(1998)) + 2*msPerHour );
170
171   addNewTestCase ( new Date(1998,9,25,1,59,59,999),
172   "new Date(1998,9,25,1,59,59,999)",
173   [DST_END_1998-1,1998,9,25,0,8,59,59,999,1998,9,25,0,1,59,59,999] );
174
175   addNewTestCase ( new Date(1998,9,25,2,0,0,0),
176   "new Date(1998,9,25,2,0,0,0)",
177   [DST_END_1998,1998,9,25,0,9,0,0,0,1998,9,25,0,1,0,0,0] );
178 */
179
180 test();
181
182 function addNewTestCase( DateCase, DateString, ResultArray ) {
183   //adjust hard-coded ResultArray for tester's timezone instead of PST
184   adjustResultArray(ResultArray);
185
186
187   new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME],       DateCase.getTime() );
188   new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME],       DateCase.valueOf() );
189
190   new TestCase( SECTION, DateString+".getUTCFullYear()",      ResultArray[UTC_YEAR],  DateCase.getUTCFullYear() );
191   new TestCase( SECTION, DateString+".getUTCMonth()",         ResultArray[UTC_MONTH],  DateCase.getUTCMonth() );
192   new TestCase( SECTION, DateString+".getUTCDate()",          ResultArray[UTC_DATE],   DateCase.getUTCDate() );
193   new TestCase( SECTION, DateString+".getUTCDay()",           ResultArray[UTC_DAY],    DateCase.getUTCDay() );
194   new TestCase( SECTION, DateString+".getUTCHours()",         ResultArray[UTC_HOURS],  DateCase.getUTCHours() );
195   new TestCase( SECTION, DateString+".getUTCMinutes()",       ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
196   new TestCase( SECTION, DateString+".getUTCSeconds()",       ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
197   new TestCase( SECTION, DateString+".getUTCMilliseconds()",  ResultArray[UTC_MS],     DateCase.getUTCMilliseconds() );
198
199   new TestCase( SECTION, DateString+".getFullYear()",         ResultArray[YEAR],       DateCase.getFullYear() );
200   new TestCase( SECTION, DateString+".getMonth()",            ResultArray[MONTH],      DateCase.getMonth() );
201   new TestCase( SECTION, DateString+".getDate()",             ResultArray[DATE],       DateCase.getDate() );
202   new TestCase( SECTION, DateString+".getDay()",              ResultArray[DAY],        DateCase.getDay() );
203   new TestCase( SECTION, DateString+".getHours()",            ResultArray[HOURS],      DateCase.getHours() );
204   new TestCase( SECTION, DateString+".getMinutes()",          ResultArray[MINUTES],    DateCase.getMinutes() );
205   new TestCase( SECTION, DateString+".getSeconds()",          ResultArray[SECONDS],    DateCase.getSeconds() );
206   new TestCase( SECTION, DateString+".getMilliseconds()",     ResultArray[MS],         DateCase.getMilliseconds() );
207 }