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