]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.5.37-2.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
23 File Name: 15.9.5.37-1.js
24 ECMA Section: 15.9.5.37 Date.prototype.setUTCFullYear(year [, mon [, date ]] )
27 If mon is not specified, this behaves as if mon were specified with the
28 value getUTCMonth( ). If date is not specified, this behaves as if date
29 were specified with the value getUTCDate( ).
31 1. Let t be this time value; but if this time value is NaN, let t be +0.
32 2. Call ToNumber(year).
33 3. If mon is not specified, compute MonthFromTime(t); otherwise, call
35 4. If date is not specified, compute DateFromTime(t); otherwise, call
37 5. Compute MakeDay(Result(2), Result(3), Result(4)).
38 6. Compute MakeDate(Result(5), TimeWithinDay(t)).
39 7. Set the [[Value]] property of the this value to TimeClip(Result(6)).
40 8. Return the value of the [[Value]] property of the this value.
42 Author: christine@netscape.com
43 Date: 12 november 1997
45 Added some Year 2000 test cases.
47 var SECTION
= "15.9.5.37-1";
48 var VERSION
= "ECMA_1";
51 writeHeaderToLog( SECTION
+ " Date.prototype.setUTCFullYear(year [, mon [, date ]] )");
57 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
58 testcases
[tc
].passed
= writeTestCaseResult(
61 testcases
[tc
].description
+" = "+
62 testcases
[tc
].actual
);
64 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
70 function getTestCases() {
74 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2000);TDATE",
75 UTCDateFromTime(SetUTCFullYear(0,2000)),
76 LocalDateFromTime(SetUTCFullYear(0,2000)) );
78 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2001);TDATE",
79 UTCDateFromTime(SetUTCFullYear(0,2001)),
80 LocalDateFromTime(SetUTCFullYear(0,2001)) );
82 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1999);TDATE",
83 UTCDateFromTime(SetUTCFullYear(0,1999)),
84 LocalDateFromTime(SetUTCFullYear(0,1999)) );
86 // Dates around 29 February 2000
88 var UTC_FEB_29_1972 = TIME_1970 + TimeInYear(1970) + TimeInYear(1971) +
89 31*msPerDay + 28*msPerDay;
91 var PST_FEB_29_1972 = UTC_FEB_29_1972 - TZ_DIFF * msPerHour;
93 addNewTestCase( "TDATE = new Date("+UTC_FEB_29_1972+"); "+
94 "TDATE.setUTCFullYear(2000);TDATE",
95 UTCDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)),
96 LocalDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)) );
98 addNewTestCase( "TDATE = new Date("+PST_FEB_29_1972+"); "+
99 "TDATE.setUTCFullYear(2000);TDATE",
100 UTCDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)),
101 LocalDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)) );
105 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2005);TDATE",
106 UTCDateFromTime(SetUTCFullYear(0,2005)),
107 LocalDateFromTime(SetUTCFullYear(0,2005)) );
109 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2004);TDATE",
110 UTCDateFromTime(SetUTCFullYear(0,2004)),
111 LocalDateFromTime(SetUTCFullYear(0,2004)) );
113 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(2006);TDATE",
114 UTCDateFromTime(SetUTCFullYear(0,2006)),
115 LocalDateFromTime(SetUTCFullYear(0,2006)) );
119 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1900);TDATE",
120 UTCDateFromTime(SetUTCFullYear(0,1900)),
121 LocalDateFromTime(SetUTCFullYear(0,1900)) );
123 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1899);TDATE",
124 UTCDateFromTime(SetUTCFullYear(0,1899)),
125 LocalDateFromTime(SetUTCFullYear(0,1899)) );
127 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1901);TDATE",
128 UTCDateFromTime(SetUTCFullYear(0,1901)),
129 LocalDateFromTime(SetUTCFullYear(0,1901)) );
133 function addNewTestCase( DateString
, UTCDate
, LocalDate
) {
134 DateCase
= eval( DateString
);
136 var item
= testcases
.length
;
138 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
140 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", UTCDate
.value
, DateCase
.getTime() );
141 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", UTCDate
.value
, DateCase
.valueOf() );
143 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", UTCDate
.year
, DateCase
.getUTCFullYear() );
144 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", UTCDate
.month
, DateCase
.getUTCMonth() );
145 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", UTCDate
.date
, DateCase
.getUTCDate() );
146 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDay()", UTCDate
.day
, DateCase
.getUTCDay() );
147 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", UTCDate
.hours
, DateCase
.getUTCHours() );
148 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", UTCDate
.minutes
,DateCase
.getUTCMinutes() );
149 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", UTCDate
.seconds
,DateCase
.getUTCSeconds() );
150 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", UTCDate
.ms
, DateCase
.getUTCMilliseconds() );
152 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", LocalDate
.year
, DateCase
.getFullYear() );
153 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", LocalDate
.month
, DateCase
.getMonth() );
154 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", LocalDate
.date
, DateCase
.getDate() );
155 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDay()", LocalDate
.day
, DateCase
.getDay() );
156 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", LocalDate
.hours
, DateCase
.getHours() );
157 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", LocalDate
.minutes
, DateCase
.getMinutes() );
158 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", LocalDate
.seconds
, DateCase
.getSeconds() );
159 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", LocalDate
.ms
, DateCase
.getMilliseconds() );
161 DateCase
.toString
= Object
.prototype.toString
;
163 testcases
[item
++] = new TestCase( SECTION
,
164 DateString
+".toString=Object.prototype.toString;"+DateString
+".toString()",
166 DateCase
.toString() );
178 function LocalDateFromTime(t
) {
180 return ( MyDateFromTime(t
) );
182 function UTCDateFromTime(t
) {
183 return ( MyDateFromTime(t
) );
185 function MyDateFromTime( t
) {
186 var d
= new MyDate();
187 d
.year
= YearFromTime(t
);
188 d
.month
= MonthFromTime(t
);
189 d
.date
= DateFromTime(t
);
190 d
.hours
= HourFromTime(t
);
191 d
.minutes
= MinFromTime(t
);
192 d
.seconds
= SecFromTime(t
);
193 d
.ms
= msFromTime(t
);
195 d
.time
= MakeTime( d
.hours
, d
.minutes
, d
.seconds
, d
.ms
);
196 d
.value
= TimeClip( MakeDate( MakeDay( d
.year
, d
.month
, d
.date
), d
.time
) );
197 d
.day
= WeekDay( d
.value
);
201 function SetUTCFullYear( t
, year
, mon
, date
) {
202 var T
= ( t
!= t
) ? 0 : t
;
203 var YEAR
= Number(year
);
204 var MONTH
= ( mon
== void 0 ) ? MonthFromTime(T
) : Number( mon
);
205 var DATE
= ( date
== void 0 ) ? DateFromTime(T
) : Number( date
);
206 var DAY
= MakeDay( YEAR
, MONTH
, DATE
);
208 return ( TimeClip(MakeDate(DAY
, TimeWithinDay(T
))) );