]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.5.36-4.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.36-1.js
24 ECMA Section: 15.9.5.36 Date.prototype.setFullYear(year [, mon [, date ]] )
27 If mon is not specified, this behaves as if mon were specified with the
28 value getMonth( ). If date is not specified, this behaves as if date were
29 specified with the value getDate( ).
31 1. Let t be the result of LocalTime(this time value); but if this time
32 value is NaN, let t be +0.
33 2. Call ToNumber(year).
34 3. If mon is not specified, compute MonthFromTime(t); otherwise, call
36 4. If date is not specified, compute DateFromTime(t); otherwise, call
38 5. Compute MakeDay(Result(2), Result(3), Result(4)).
39 6. Compute UTC(MakeDate(Result(5), TimeWithinDay(t))).
40 7. Set the [[Value]] property of the this value to TimeClip(Result(6)).
41 8. Return the value of the [[Value]] property of the this value.
43 Author: christine@netscape.com
44 Date: 12 november 1997
46 Added test cases for Year 2000 Compatilibity Testing.
49 var SECTION
= "15.9.5.36-1";
50 var VERSION
= "ECMA_1";
53 writeHeaderToLog( SECTION
+ " Date.prototype.setFullYear(year [, mon [, date ]] )");
59 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
60 testcases
[tc
].passed
= writeTestCaseResult(
63 testcases
[tc
].description
+" = "+
64 testcases
[tc
].actual
);
66 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
71 function getTestCases() {
73 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1999);TDATE",
74 UTCDateFromTime(SetFullYear(0,1999)),
75 LocalDateFromTime(SetFullYear(0,1999)) );
77 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1999,11);TDATE",
78 UTCDateFromTime(SetFullYear(0,1999,11)),
79 LocalDateFromTime(SetFullYear(0,1999,11)) );
81 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1999,11,31);TDATE",
82 UTCDateFromTime(SetFullYear(0,1999,11,31)),
83 LocalDateFromTime(SetFullYear(0,1999,11,31)) );
87 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000);TDATE",
88 UTCDateFromTime(SetFullYear(0,2000)),
89 LocalDateFromTime(SetFullYear(0,2000)) );
91 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,0);TDATE",
92 UTCDateFromTime(SetFullYear(0,2000,0)),
93 LocalDateFromTime(SetFullYear(0,2000,0)) );
95 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,0,1);TDATE",
96 UTCDateFromTime(SetFullYear(0,2000,0,1)),
97 LocalDateFromTime(SetFullYear(0,2000,0,1)) );
100 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000);TDATE",
101 UTCDateFromTime(SetFullYear(0,2000)),
102 LocalDateFromTime(SetFullYear(0,2000)) );
104 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,1);TDATE",
105 UTCDateFromTime(SetFullYear(0,2000,1)),
106 LocalDateFromTime(SetFullYear(0,2000,1)) );
108 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,1,29);TDATE",
109 UTCDateFromTime(SetFullYear(0,2000,1,29)),
110 LocalDateFromTime(SetFullYear(0,2000,1,29)) );
113 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005);TDATE",
114 UTCDateFromTime(SetFullYear(0,2005)),
115 LocalDateFromTime(SetFullYear(0,2005)) );
117 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005,0);TDATE",
118 UTCDateFromTime(SetFullYear(0,2005,0)),
119 LocalDateFromTime(SetFullYear(0,2005,0)) );
121 addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005,0,1);TDATE",
122 UTCDateFromTime(SetFullYear(0,2005,0,1)),
123 LocalDateFromTime(SetFullYear(0,2005,0,1)) );
127 function addNewTestCase( DateString
, UTCDate
, LocalDate
) {
128 DateCase
= eval( DateString
);
130 var item
= testcases
.length
;
132 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
134 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", UTCDate
.value
, DateCase
.getTime() );
135 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", UTCDate
.value
, DateCase
.valueOf() );
137 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", UTCDate
.year
, DateCase
.getUTCFullYear() );
138 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", UTCDate
.month
, DateCase
.getUTCMonth() );
139 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", UTCDate
.date
, DateCase
.getUTCDate() );
140 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDay()", UTCDate
.day
, DateCase
.getUTCDay() );
141 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", UTCDate
.hours
, DateCase
.getUTCHours() );
142 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", UTCDate
.minutes
,DateCase
.getUTCMinutes() );
143 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", UTCDate
.seconds
,DateCase
.getUTCSeconds() );
144 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", UTCDate
.ms
, DateCase
.getUTCMilliseconds() );
146 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", LocalDate
.year
, DateCase
.getFullYear() );
147 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", LocalDate
.month
, DateCase
.getMonth() );
148 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", LocalDate
.date
, DateCase
.getDate() );
149 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDay()", LocalDate
.day
, DateCase
.getDay() );
150 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", LocalDate
.hours
, DateCase
.getHours() );
151 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", LocalDate
.minutes
, DateCase
.getMinutes() );
152 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", LocalDate
.seconds
, DateCase
.getSeconds() );
153 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", LocalDate
.ms
, DateCase
.getMilliseconds() );
155 DateCase
.toString
= Object
.prototype.toString
;
157 testcases
[item
++] = new TestCase( SECTION
,
158 DateString
+".toString=Object.prototype.toString;"+DateString
+".toString()",
160 DateCase
.toString() );
172 function LocalDateFromTime(t
) {
174 return ( MyDateFromTime(t
) );
176 function UTCDateFromTime(t
) {
177 return ( MyDateFromTime(t
) );
179 function MyDateFromTime( t
) {
180 var d
= new MyDate();
181 d
.year
= YearFromTime(t
);
182 d
.month
= MonthFromTime(t
);
183 d
.date
= DateFromTime(t
);
184 d
.hours
= HourFromTime(t
);
185 d
.minutes
= MinFromTime(t
);
186 d
.seconds
= SecFromTime(t
);
187 d
.ms
= msFromTime(t
);
189 d
.time
= MakeTime( d
.hours
, d
.minutes
, d
.seconds
, d
.ms
);
190 d
.value
= TimeClip( MakeDate( MakeDay( d
.year
, d
.month
, d
.date
), d
.time
) );
191 d
.day
= WeekDay( d
.value
);
195 function SetFullYear( t
, year
, mon
, date
) {
196 var T
= ( isNaN(t
) ) ? 0 : LocalTime(t
) ;
197 var YEAR
= Number( year
);
198 var MONTH
= ( mon
== void 0 ) ? MonthFromTime(T
) : Number( mon
);
199 var DATE
= ( date
== void 0 ) ? DateFromTime(T
) : Number( date
);
201 var DAY
= MakeDay( YEAR
, MONTH
, DATE
);
202 var UTC_DATE
= UTC(MakeDate( DAY
, TimeWithinDay(T
)));
204 return ( TimeClip(UTC_DATE
) );