]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
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 | File Name: 15.9.5.36-1.js | |
24 | ECMA Section: 15.9.5.36 Date.prototype.setFullYear(year [, mon [, date ]] ) | |
25 | Description: | |
26 | ||
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( ). | |
30 | ||
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 | |
35 | ToNumber(mon). | |
36 | 4. If date is not specified, compute DateFromTime(t); otherwise, call | |
37 | ToNumber(date). | |
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. | |
42 | ||
43 | Author: christine@netscape.com | |
44 | Date: 12 november 1997 | |
45 | ||
46 | Added test cases for Year 2000 Compatilibity Testing. | |
47 | ||
48 | */ | |
49 | var SECTION = "15.9.5.36-1"; | |
50 | var VERSION = "ECMA_1"; | |
51 | startTest(); | |
52 | ||
53 | writeHeaderToLog( SECTION + " Date.prototype.setFullYear(year [, mon [, date ]] )"); | |
54 | ||
55 | getTestCases(); | |
56 | test(); | |
57 | ||
58 | function test() { | |
59 | for ( tc=0; tc < testcases.length; tc++ ) { | |
60 | testcases[tc].passed = writeTestCaseResult( | |
61 | testcases[tc].expect, | |
62 | testcases[tc].actual, | |
63 | testcases[tc].description +" = "+ | |
64 | testcases[tc].actual ); | |
65 | ||
66 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
67 | } | |
68 | stopTest(); | |
69 | return ( testcases ); | |
70 | } | |
71 | function getTestCases() { | |
72 | // 1971 | |
73 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1971);TDATE", | |
74 | UTCDateFromTime(SetFullYear(0,1971)), | |
75 | LocalDateFromTime(SetFullYear(0,1971)) ); | |
76 | ||
77 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1971,0);TDATE", | |
78 | UTCDateFromTime(SetFullYear(0,1971,0)), | |
79 | LocalDateFromTime(SetFullYear(0,1971,0)) ); | |
80 | ||
81 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1971,0,1);TDATE", | |
82 | UTCDateFromTime(SetFullYear(0,1971,0,1)), | |
83 | LocalDateFromTime(SetFullYear(0,1971,0,1)) ); | |
84 | ||
85 | /* | |
86 | // 1999 | |
87 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1999);TDATE", | |
88 | UTCDateFromTime(SetFullYear(0,1999)), | |
89 | LocalDateFromTime(SetFullYear(0,1999)) ); | |
90 | ||
91 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1999,11);TDATE", | |
92 | UTCDateFromTime(SetFullYear(0,1999,11)), | |
93 | LocalDateFromTime(SetFullYear(0,1999,11)) ); | |
94 | ||
95 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1999,11,31);TDATE", | |
96 | UTCDateFromTime(SetFullYear(0,1999,11,31)), | |
97 | LocalDateFromTime(SetFullYear(0,1999,11,31)) ); | |
98 | ||
99 | // 2000 | |
100 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000);TDATE", | |
101 | UTCDateFromTime(SetFullYear(0,2000)), | |
102 | LocalDateFromTime(SetFullYear(0,2000)) ); | |
103 | ||
104 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,0);TDATE", | |
105 | UTCDateFromTime(SetFullYear(0,2000,0)), | |
106 | LocalDateFromTime(SetFullYear(0,2000,0)) ); | |
107 | ||
108 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,0,1);TDATE", | |
109 | UTCDateFromTime(SetFullYear(0,2000,0,1)), | |
110 | LocalDateFromTime(SetFullYear(0,2000,0,1)) ); | |
111 | ||
112 | // feb 29, 2000 | |
113 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000);TDATE", | |
114 | UTCDateFromTime(SetFullYear(0,2000)), | |
115 | LocalDateFromTime(SetFullYear(0,2000)) ); | |
116 | ||
117 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,1);TDATE", | |
118 | UTCDateFromTime(SetFullYear(0,2000,1)), | |
119 | LocalDateFromTime(SetFullYear(0,2000,1)) ); | |
120 | ||
121 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,1,29);TDATE", | |
122 | UTCDateFromTime(SetFullYear(0,2000,1,29)), | |
123 | LocalDateFromTime(SetFullYear(0,2000,1,29)) ); | |
124 | ||
125 | // Jan 1, 2005 | |
126 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005);TDATE", | |
127 | UTCDateFromTime(SetFullYear(0,2005)), | |
128 | LocalDateFromTime(SetFullYear(0,2005)) ); | |
129 | ||
130 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005,0);TDATE", | |
131 | UTCDateFromTime(SetFullYear(0,2005,0)), | |
132 | LocalDateFromTime(SetFullYear(0,2005,0)) ); | |
133 | ||
134 | addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005,0,1);TDATE", | |
135 | UTCDateFromTime(SetFullYear(0,2005,0,1)), | |
136 | LocalDateFromTime(SetFullYear(0,2005,0,1)) ); | |
137 | ||
138 | */ | |
139 | } | |
140 | function addNewTestCase( DateString, UTCDate, LocalDate) { | |
141 | DateCase = eval( DateString ); | |
142 | ||
143 | var item = testcases.length; | |
144 | ||
145 | // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year; | |
146 | ||
147 | testcases[item++] = new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); | |
148 | testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); | |
149 | ||
150 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); | |
151 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); | |
152 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); | |
153 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() ); | |
154 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); | |
155 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); | |
156 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); | |
157 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); | |
158 | ||
159 | testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); | |
160 | testcases[item++] = new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); | |
161 | testcases[item++] = new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); | |
162 | testcases[item++] = new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() ); | |
163 | testcases[item++] = new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); | |
164 | testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); | |
165 | testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); | |
166 | testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); | |
167 | ||
168 | DateCase.toString = Object.prototype.toString; | |
169 | ||
170 | testcases[item++] = new TestCase( SECTION, | |
171 | DateString+".toString=Object.prototype.toString;"+DateString+".toString()", | |
172 | "[object Date]", | |
173 | DateCase.toString() ); | |
174 | } | |
175 | ||
176 | function MyDate() { | |
177 | this.year = 0; | |
178 | this.month = 0; | |
179 | this.date = 0; | |
180 | this.hours = 0; | |
181 | this.minutes = 0; | |
182 | this.seconds = 0; | |
183 | this.ms = 0; | |
184 | } | |
185 | function LocalDateFromTime(t) { | |
186 | t = LocalTime(t); | |
187 | return ( MyDateFromTime(t) ); | |
188 | } | |
189 | function UTCDateFromTime(t) { | |
190 | return ( MyDateFromTime(t) ); | |
191 | } | |
192 | function MyDateFromTime( t ) { | |
193 | var d = new MyDate(); | |
194 | d.year = YearFromTime(t); | |
195 | d.month = MonthFromTime(t); | |
196 | d.date = DateFromTime(t); | |
197 | d.hours = HourFromTime(t); | |
198 | d.minutes = MinFromTime(t); | |
199 | d.seconds = SecFromTime(t); | |
200 | d.ms = msFromTime(t); | |
201 | ||
202 | d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); | |
203 | d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); | |
204 | d.day = WeekDay( d.value ); | |
205 | ||
206 | return (d); | |
207 | } | |
208 | function SetFullYear( t, year, mon, date ) { | |
209 | var T = ( isNaN(t) ) ? 0 : LocalTime(t) ; | |
210 | var YEAR = Number( year ); | |
211 | var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon ); | |
212 | var DATE = ( date == void 0 ) ? DateFromTime(T) : Number( date ); | |
213 | ||
214 | var DAY = MakeDay( YEAR, MONTH, DATE ); | |
215 | var UTC_DATE = UTC(MakeDate( DAY, TimeWithinDay(T))); | |
216 | ||
217 | return ( TimeClip(UTC_DATE) ); | |
218 | } |