* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Microsoft.JScript / Test / Mozilla / ecma / Date / 15.9.4.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 var testcases = new Array();
41 var SECTION = "15.9.4.3";
42 var TITLE = "Date.UTC( year, month, date, hours, minutes, seconds, ms )";
43
44 // Dates around 1970
45
46 addNewTestCase( Date.UTC( 1970,0,1,0,0,0,0),
47                 "Date.UTC( 1970,0,1,0,0,0,0)",
48                 utc(1970,0,1,0,0,0,0) );
49
50 addNewTestCase( Date.UTC( 1969,11,31,23,59,59,999),
51                 "Date.UTC( 1969,11,31,23,59,59,999)",
52                 utc(1969,11,31,23,59,59,999) );
53 addNewTestCase( Date.UTC( 1972,1,29,23,59,59,999),
54                 "Date.UTC( 1972,1,29,23,59,59,999)",
55                 utc(1972,1,29,23,59,59,999) );
56 addNewTestCase( Date.UTC( 1972,2,1,23,59,59,999),
57                 "Date.UTC( 1972,2,1,23,59,59,999)",
58                 utc(1972,2,1,23,59,59,999) );
59 addNewTestCase( Date.UTC( 1968,1,29,23,59,59,999),
60                 "Date.UTC( 1968,1,29,23,59,59,999)",
61                 utc(1968,1,29,23,59,59,999) );
62 addNewTestCase( Date.UTC( 1968,2,1,23,59,59,999),
63                 "Date.UTC( 1968,2,1,23,59,59,999)",
64                 utc(1968,2,1,23,59,59,999) );
65 addNewTestCase( Date.UTC( 1969,0,1,0,0,0,0),
66                 "Date.UTC( 1969,0,1,0,0,0,0)",
67                 utc(1969,0,1,0,0,0,0) );
68 addNewTestCase( Date.UTC( 1969,11,31,23,59,59,1000),
69                 "Date.UTC( 1969,11,31,23,59,59,1000)",
70                 utc(1970,0,1,0,0,0,0) );
71 addNewTestCase( Date.UTC( 1969,Number.NaN,31,23,59,59,999),
72                 "Date.UTC( 1969,Number.NaN,31,23,59,59,999)",
73                 utc(1969,Number.NaN,31,23,59,59,999) );
74
75 // Dates around 2000
76
77 addNewTestCase( Date.UTC( 1999,11,31,23,59,59,999),
78                 "Date.UTC( 1999,11,31,23,59,59,999)",
79                 utc(1999,11,31,23,59,59,999) );
80 addNewTestCase( Date.UTC( 2000,0,1,0,0,0,0),
81                 "Date.UTC( 2000,0,1,0,0,0,0)",
82                 utc(2000,0,1,0,0,0,0) );
83
84 // Dates around 1900
85 addNewTestCase( Date.UTC( 1899,11,31,23,59,59,999),
86                 "Date.UTC( 1899,11,31,23,59,59,999)",
87                 utc(1899,11,31,23,59,59,999) );
88 addNewTestCase( Date.UTC( 1900,0,1,0,0,0,0),
89                 "Date.UTC( 1900,0,1,0,0,0,0)",
90                 utc(1900,0,1,0,0,0,0) );
91 addNewTestCase( Date.UTC( 1973,0,1,0,0,0,0),
92                 "Date.UTC( 1973,0,1,0,0,0,0)",
93                 utc(1973,0,1,0,0,0,0) );
94 addNewTestCase( Date.UTC( 1776,6,4,12,36,13,111),
95                 "Date.UTC( 1776,6,4,12,36,13,111)",
96                 utc(1776,6,4,12,36,13,111) );
97 addNewTestCase( Date.UTC( 2525,9,18,15,30,1,123),
98                 "Date.UTC( 2525,9,18,15,30,1,123)",
99                 utc(2525,9,18,15,30,1,123) );
100
101 // Dates around 29 Feb 2000
102
103 addNewTestCase( Date.UTC( 2000,1,29,0,0,0,0 ),
104                 "Date.UTC( 2000,1,29,0,0,0,0 )",
105                 utc(2000,1,29,0,0,0,0) );
106 addNewTestCase( Date.UTC( 2000,1,29,8,0,0,0 ),
107                 "Date.UTC( 2000,1,29,8,0,0,0 )",
108                 utc(2000,1,29,8,0,0,0) );
109
110 // Dates around 1 Jan 2005
111
112 addNewTestCase( Date.UTC( 2005,0,1,0,0,0,0 ),
113                 "Date.UTC( 2005,0,1,0,0,0,0 )",
114                 utc(2005,0,1,0,0,0,0) );
115 addNewTestCase( Date.UTC( 2004,11,31,16,0,0,0 ),
116                 "Date.UTC( 2004,11,31,16,0,0,0 )",
117                 utc(2004,11,31,16,0,0,0) );
118
119 test();
120
121 function addNewTestCase( DateCase, DateString, ExpectDate) {
122   DateCase = DateCase;
123
124
125 //    fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
126
127   new TestCase( SECTION, DateString,         ExpectDate.value,       DateCase );
128   new TestCase( SECTION, DateString,         ExpectDate.value,       DateCase );
129 /*
130
131 new TestCase( SECTION, DateString+".getUTCFullYear()",        ExpectDate.year,   DateCase.getUTCFullYear() );
132 new TestCase( SECTION, DateString+".getUTCMonth()",         ExpectDate.month,  DateCase.getUTCMonth() );
133 new TestCase( SECTION, DateString+".getUTCDate()",          ExpectDate.date,   DateCase.getUTCDate() );
134 new TestCase( SECTION, DateString+".getUTCDay()",           ExpectDate.day,    DateCase.getUTCDay() );
135 new TestCase( SECTION, DateString+".getUTCHours()",         ExpectDate.hours,  DateCase.getUTCHours() );
136 new TestCase( SECTION, DateString+".getUTCMinutes()",       ExpectDate.minutes,DateCase.getUTCMinutes() );
137 new TestCase( SECTION, DateString+".getUTCSeconds()",       ExpectDate.seconds,DateCase.getUTCSeconds() );
138 new TestCase( SECTION, DateString+".getUTCMilliseconds()",  ExpectDate.ms,     DateCase.getUTCMilliseconds() );
139
140 new TestCase( SECTION, DateString+".getFullYear()",             ExpectDate.year,            DateCase.getFullYear() );
141 new TestCase( SECTION, DateString+".getMonth()",            ExpectDate.month,      DateCase.getMonth() );
142 new TestCase( SECTION, DateString+".getDate()",             ExpectDate.date,       DateCase.getDate() );
143 //    new TestCase( SECTION, DateString+".getDay()",              ExpectDate.day,        DateCase.getDay() );
144 new TestCase( SECTION, DateString+".getHours()",            ExpectDate.hours,      DateCase.getHours() );
145 new TestCase( SECTION, DateString+".getMinutes()",          ExpectDate.minutes,    DateCase.getMinutes() );
146 new TestCase( SECTION, DateString+".getSeconds()",          ExpectDate.seconds,    DateCase.getSeconds() );
147 new TestCase( SECTION, DateString+".getMilliseconds()",     ExpectDate.ms,         DateCase.getMilliseconds() );
148 */
149 }
150
151 function MyDate() {
152   this.year = 0;
153   this.month = 0;
154   this.date = 0;
155   this.hours = 0;
156   this.minutes = 0;
157   this.seconds = 0;
158   this.ms = 0;
159 }
160
161 function utc( year, month, date, hours, minutes, seconds, ms ) {
162   var d = new MyDate();
163   d.year      = Number(year);
164
165   if (month)
166     d.month     = Number(month);
167   if (date)
168     d.date      = Number(date);
169   if (hours)
170     d.hours     = Number(hours);
171   if (minutes)
172     d.minutes   = Number(minutes);
173   if (seconds)
174     d.seconds   = Number(seconds);
175   if (ms)
176     d.ms        = Number(ms);
177
178   if ( isNaN(d.year) && 0 <= ToInteger(d.year) && d.year <= 99 ) {
179     d.year = 1900 + ToInteger(d.year);
180   }
181
182   if (isNaN(month) || isNaN(year) || isNaN(date) || isNaN(hours) ||
183       isNaN(minutes) || isNaN(seconds) || isNaN(ms) ) {
184     d.year = Number.NaN;
185     d.month = Number.NaN;
186     d.date = Number.NaN;
187     d.hours = Number.NaN;
188     d.minutes = Number.NaN;
189     d.seconds = Number.NaN;
190     d.ms = Number.NaN;
191     d.value = Number.NaN;
192     d.time = Number.NaN;
193     d.day =Number.NaN;
194     return d;
195   }
196
197   d.day = MakeDay( d.year, d.month, d.date );
198   d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
199   d.value = (TimeClip( MakeDate(d.day,d.time)));
200
201   return d;
202 }
203
204 function UTCTime( t ) {
205   sign = ( t < 0 ) ? -1 : 1;
206   return ( (t +(TZ_DIFF*msPerHour)) );
207 }
208