• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
58function 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}
71function getTestCases() {
72
73    // 1969
74
75    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1969);TDATE",
76                    UTCDateFromTime(SetFullYear(0,1969)),
77                    LocalDateFromTime(SetFullYear(0,1969)) );
78
79    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1969,11);TDATE",
80                    UTCDateFromTime(SetFullYear(0,1969,11)),
81                    LocalDateFromTime(SetFullYear(0,1969,11)) );
82
83    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1969,11,31);TDATE",
84                    UTCDateFromTime(SetFullYear(0,1969,11,31)),
85                    LocalDateFromTime(SetFullYear(0,1969,11,31)) );
86/*
87    // 1970
88
89    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1970);TDATE",
90                    UTCDateFromTime(SetFullYear(0,1970)),
91                    LocalDateFromTime(SetFullYear(0,1970)) );
92
93    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1970,0);TDATE",
94                    UTCDateFromTime(SetFullYear(0,1970,0)),
95                    LocalDateFromTime(SetFullYear(0,1970,0)) );
96
97    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1970,0,1);TDATE",
98                    UTCDateFromTime(SetFullYear(0,1970,0,1)),
99                    LocalDateFromTime(SetFullYear(0,1970,0,1)) );
100    // 1971
101    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1971);TDATE",
102                    UTCDateFromTime(SetFullYear(0,1971)),
103                    LocalDateFromTime(SetFullYear(0,1971)) );
104
105    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1971,0);TDATE",
106                    UTCDateFromTime(SetFullYear(0,1971,0)),
107                    LocalDateFromTime(SetFullYear(0,1971,0)) );
108
109    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1971,0,1);TDATE",
110                    UTCDateFromTime(SetFullYear(0,1971,0,1)),
111                    LocalDateFromTime(SetFullYear(0,1971,0,1)) );
112
113    // 1999
114    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1999);TDATE",
115                    UTCDateFromTime(SetFullYear(0,1999)),
116                    LocalDateFromTime(SetFullYear(0,1999)) );
117
118    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1999,11);TDATE",
119                    UTCDateFromTime(SetFullYear(0,1999,11)),
120                    LocalDateFromTime(SetFullYear(0,1999,11)) );
121
122    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1999,11,31);TDATE",
123                    UTCDateFromTime(SetFullYear(0,1999,11,31)),
124                    LocalDateFromTime(SetFullYear(0,1999,11,31)) );
125
126    // 2000
127    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000);TDATE",
128                    UTCDateFromTime(SetFullYear(0,2000)),
129                    LocalDateFromTime(SetFullYear(0,2000)) );
130
131    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,0);TDATE",
132                    UTCDateFromTime(SetFullYear(0,2000,0)),
133                    LocalDateFromTime(SetFullYear(0,2000,0)) );
134
135    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,0,1);TDATE",
136                    UTCDateFromTime(SetFullYear(0,2000,0,1)),
137                    LocalDateFromTime(SetFullYear(0,2000,0,1)) );
138
139    // feb 29, 2000
140    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000);TDATE",
141                    UTCDateFromTime(SetFullYear(0,2000)),
142                    LocalDateFromTime(SetFullYear(0,2000)) );
143
144    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,1);TDATE",
145                    UTCDateFromTime(SetFullYear(0,2000,1)),
146                    LocalDateFromTime(SetFullYear(0,2000,1)) );
147
148    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,1,29);TDATE",
149                    UTCDateFromTime(SetFullYear(0,2000,1,29)),
150                    LocalDateFromTime(SetFullYear(0,2000,1,29)) );
151
152    // Jan 1, 2005
153    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005);TDATE",
154                    UTCDateFromTime(SetFullYear(0,2005)),
155                    LocalDateFromTime(SetFullYear(0,2005)) );
156
157    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005,0);TDATE",
158                    UTCDateFromTime(SetFullYear(0,2005,0)),
159                    LocalDateFromTime(SetFullYear(0,2005,0)) );
160
161    addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2005,0,1);TDATE",
162                    UTCDateFromTime(SetFullYear(0,2005,0,1)),
163                    LocalDateFromTime(SetFullYear(0,2005,0,1)) );
164
165*/
166}
167function addNewTestCase( DateString, UTCDate, LocalDate) {
168    DateCase = eval( DateString );
169
170    var 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+".getTime()",             UTCDate.value,       DateCase.getTime() );
175    testcases[item++] = new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
176
177    testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
178    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
179    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
180    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
181    testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
182    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
183    testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
184    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
185
186    testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
187    testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
188    testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
189    testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
190    testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
191    testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
192    testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
193    testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
194
195    DateCase.toString = Object.prototype.toString;
196
197    testcases[item++] = new TestCase( SECTION,
198                                      DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
199                                      "[object Date]",
200                                      DateCase.toString() );
201}
202
203function MyDate() {
204    this.year = 0;
205    this.month = 0;
206    this.date = 0;
207    this.hours = 0;
208    this.minutes = 0;
209    this.seconds = 0;
210    this.ms = 0;
211}
212function LocalDateFromTime(t) {
213    t = LocalTime(t);
214    return ( MyDateFromTime(t) );
215}
216function UTCDateFromTime(t) {
217 return ( MyDateFromTime(t) );
218}
219function MyDateFromTime( t ) {
220    var d = new MyDate();
221    d.year = YearFromTime(t);
222    d.month = MonthFromTime(t);
223    d.date = DateFromTime(t);
224    d.hours = HourFromTime(t);
225    d.minutes = MinFromTime(t);
226    d.seconds = SecFromTime(t);
227    d.ms = msFromTime(t);
228
229    d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
230    d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
231    d.day = WeekDay( d.value );
232
233    return (d);
234}
235function SetFullYear( t, year, mon, date ) {
236    var T = ( isNaN(t) ) ? 0 : LocalTime(t) ;
237    var YEAR = Number( year );
238    var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon );
239    var DATE = ( date == void 0 ) ? DateFromTime(T)  : Number( date );
240
241    var DAY = MakeDay( YEAR, MONTH, DATE );
242    var UTC_DATE = UTC(MakeDate( DAY, TimeWithinDay(T)));
243
244    return ( TimeClip(UTC_DATE) );
245}