]>
git.saurik.com Git - apple/javascriptcore.git/blob - 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/
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.
11 * The Original Code is Mozilla Communicator client code, released March
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
24 var testcases
= new Array();
25 var SECTION
= "15.9.4.3";
26 var TITLE
= "Date.UTC( year, month, date, hours, minutes, seconds, ms )";
41 function utc( year
, month
, date
, hours
, minutes
, seconds
, ms
) {
43 d
.year
= Number(year
);
46 d
.month
= Number(month
);
48 d
.date
= Number(date
);
50 d
.hours
= Number(hours
);
52 d
.minutes
= Number(minutes
);
54 d
.seconds
= Number(seconds
);
58 if ( isNaN(d
.year
) && 0 <= ToInteger(d
.year
) && d
.year
<= 99 ) {
59 d
.year
= 1900 + ToInteger(d
.year
);
62 if (isNaN(month
) || isNaN(year
) || isNaN(date
) || isNaN(hours
) ||
63 isNaN(minutes
) || isNaN(seconds
) || isNaN(ms
) ) {
68 d
.minutes
= Number
.NaN
;
69 d
.seconds
= Number
.NaN
;
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
)));
84 function UTCTime( t
) {
85 sign
= ( t
< 0 ) ? -1 : 1;
86 return ( (t
+(TZ_DIFF
*msPerHour
)) );
89 function getTestCases() {
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) );
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) );
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) );
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) );
148 // Dates around 29 Feb 2000
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) );
157 // Dates around 1 Jan 2005
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) );
167 function addNewTestCase( DateCase
, DateString
, ExpectDate
) {
170 item
= testcases
.length
;
172 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
174 testcases
[item
++] = new TestCase( SECTION
, DateString
, ExpectDate
.value
, DateCase
);
175 testcases
[item
++] = new TestCase( SECTION
, DateString
, ExpectDate
.value
, DateCase
);
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() );
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() );
198 for( tc
=0; tc
< testcases
.length
; tc
++ ) {
200 testcases
[tc
].passed
= writeTestCaseResult(
201 testcases
[tc
].expect
,
202 testcases
[tc
].actual
,
203 testcases
[tc
].description
+" = " +
204 testcases
[tc
].actual
);