initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma / Date / 15.9.5.37-5.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/
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.37-1.js
24     ECMA Section:       15.9.5.37 Date.prototype.setUTCFullYear(year [, mon [, date ]] )
25     Description:
26
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( ).
30
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
34         ToNumber(mon).
35    4.   If date is not specified, compute DateFromTime(t); otherwise, call
36         ToNumber(date).
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.
41
42     Author:             christine@netscape.com
43     Date:               12 november 1997
44
45     Added some Year 2000 test cases.
46 */
47     var SECTION = "15.9.5.37-1";
48     var VERSION = "ECMA_1";
49     startTest();
50
51     writeHeaderToLog( SECTION + " Date.prototype.setUTCFullYear(year [, mon [, date ]] )");
52
53     getTestCases();
54     test();
55
56 function test() {
57     for ( tc=0; tc < testcases.length; tc++ ) {
58         testcases[tc].passed = writeTestCaseResult(
59                             testcases[tc].expect,
60                             testcases[tc].actual,
61                             testcases[tc].description +" = "+
62                             testcases[tc].actual );
63
64         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
65     }
66     stopTest();
67     return ( testcases );
68 }
69
70 function getTestCases() {
71     // Dates around 1900
72     addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1900);TDATE",
73                     UTCDateFromTime(SetUTCFullYear(0,1900)),
74                     LocalDateFromTime(SetUTCFullYear(0,1900)) );
75
76     addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1899);TDATE",
77                     UTCDateFromTime(SetUTCFullYear(0,1899)),
78                     LocalDateFromTime(SetUTCFullYear(0,1899)) );
79
80     addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1901);TDATE",
81                     UTCDateFromTime(SetUTCFullYear(0,1901)),
82                     LocalDateFromTime(SetUTCFullYear(0,1901)) );
83 }
84 function addNewTestCase( DateString, UTCDate, LocalDate) {
85     DateCase = eval( DateString );
86
87     var item = testcases.length;
88
89 //    fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
90
91     testcases[item++] = new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
92     testcases[item++] = new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
93
94     testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
95     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
96     testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
97     testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
98     testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
99     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
100     testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
101     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
102
103     testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
104     testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
105     testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
106     testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
107     testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
108     testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
109     testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
110     testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
111
112     DateCase.toString = Object.prototype.toString;
113
114     testcases[item++] = new TestCase( SECTION,
115                                       DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
116                                       "[object Date]",
117                                       DateCase.toString() );
118 }
119
120 function MyDate() {
121     this.year = 0;
122     this.month = 0;
123     this.date = 0;
124     this.hours = 0;
125     this.minutes = 0;
126     this.seconds = 0;
127     this.ms = 0;
128 }
129 function LocalDateFromTime(t) {
130     t = LocalTime(t);
131     return ( MyDateFromTime(t) );
132 }
133 function UTCDateFromTime(t) {
134  return ( MyDateFromTime(t) );
135 }
136 function MyDateFromTime( t ) {
137     var d = new MyDate();
138     d.year = YearFromTime(t);
139     d.month = MonthFromTime(t);
140     d.date = DateFromTime(t);
141     d.hours = HourFromTime(t);
142     d.minutes = MinFromTime(t);
143     d.seconds = SecFromTime(t);
144     d.ms = msFromTime(t);
145
146     d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
147     d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
148     d.day = WeekDay( d.value );
149
150     return (d);
151 }
152 function SetUTCFullYear( t, year, mon, date ) {
153     var T = ( t != t ) ? 0 : t;
154     var YEAR = Number(year);
155     var MONTH = ( mon == void 0 ) ?     MonthFromTime(T) : Number( mon );
156     var DATE  = ( date == void 0 ) ?    DateFromTime(T)  : Number( date );
157     var DAY = MakeDay( YEAR, MONTH, DATE );
158
159     return ( TimeClip(MakeDate(DAY, TimeWithinDay(T))) );
160 }