initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma / Date / 15.9.5.34-1.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.34-1.js
24     ECMA Section:       15.9.5.34 Date.prototype.setMonth(mon [, date ] )
25     Description:
26     If date is not specified, this behaves as if date were specified with the
27     value getDate( ).
28
29     1.  Let t be the result of LocalTime(this time value).
30     2.  Call ToNumber(date).
31     3.  If date is not specified, compute DateFromTime(t); otherwise, call ToNumber(date).
32     4.  Compute MakeDay(YearFromTime(t), Result(2), Result(3)).
33     5.  Compute UTC(MakeDate(Result(4), TimeWithinDay(t))).
34     6.  Set the [[Value]] property of the this value to TimeClip(Result(5)).
35     7.  Return the value of the [[Value]] property of the this value.
36
37     Author:             christine@netscape.com
38     Date:               12 november 1997
39 */
40     var SECTION = "15.9.5.34-1";
41     var VERSION = "ECMA_1";
42     startTest();
43
44     writeHeaderToLog( SECTION + " Date.prototype.setMonth(mon [, date ] )");
45
46     var now =  (new Date()).valueOf();
47
48     getFunctionCases();
49     getTestCases();
50     test();
51
52 function test() {
53     for ( tc=0; tc < testcases.length; tc++ ) {
54         testcases[tc].passed = writeTestCaseResult(
55                             testcases[tc].expect,
56                             testcases[tc].actual,
57                             testcases[tc].description +" = "+
58                             testcases[tc].actual );
59
60         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
61     }
62     stopTest();
63     return ( testcases );
64 }
65
66 function getFunctionCases() {
67     // some tests for all functions
68     testcases[testcases.length] = new TestCase(
69                                     SECTION,
70                                     "Date.prototype.setMonth.length",
71                                     2,
72                                     Date.prototype.setMonth.length );
73
74     testcases[testcases.length] = new TestCase(
75                                     SECTION,
76                                     "typeof Date.prototype.setMonth",
77                                     "function",
78                                     typeof Date.prototype.setMonth );
79
80
81 /*
82
83     testcases[testcases.length] = new TestCase(
84                                     SECTION,
85                                     "delete Date.prototype.setMonth",
86                                     false,
87                                     delete Date.prototype.setMonth );
88 */
89
90 }
91
92
93 function getTestCases() {
94     // regression test for http://scopus.mcom.com/bugsplat/show_bug.cgi?id=112404
95     d = new Date(0);
96     d.setMonth(1,1,1,1,1,1);
97
98         addNewTestCase(
99         "TDATE = new Date(0); TDATE.setMonth(1,1,1,1,1,1); TDATE",
100         UTCDateFromTime(SetMonth(0,1,1)),
101         LocalDateFromTime(SetMonth(0,1,1)) );
102
103
104     // whatever today is
105
106     addNewTestCase( "TDATE = new Date(now); (TDATE).setMonth(11,31); TDATE",
107                     UTCDateFromTime(SetMonth(now,11,31)),
108                     LocalDateFromTime(SetMonth(now,11,31)) );
109
110     // 1970
111
112     addNewTestCase( "TDATE = new Date(0);(TDATE).setMonth(0,1);TDATE",
113                     UTCDateFromTime(SetMonth(0,0,1)),
114                     LocalDateFromTime(SetMonth(0,0,1)) );
115
116     addNewTestCase( "TDATE = new Date("+TIME_1900+"); "+
117                     "(TDATE).setMonth(11,31); TDATE",
118                     UTCDateFromTime( SetMonth(TIME_1900,11,31) ),
119                     LocalDateFromTime( SetMonth(TIME_1900,11,31) ) );
120
121
122
123
124 /*
125     addNewTestCase( "TDATE = new Date(28800000);(TDATE).setMonth(11,23,59,999);TDATE",
126                     UTCDateFromTime(SetMonth(28800000,11,23,59,999)),
127                     LocalDateFromTime(SetMonth(28800000,11,23,59,999)) );
128
129     addNewTestCase( "TDATE = new Date(28800000);(TDATE).setMonth(99,99);TDATE",
130                     UTCDateFromTime(SetMonth(28800000,99,99)),
131                     LocalDateFromTime(SetMonth(28800000,99,99)) );
132
133     addNewTestCase( "TDATE = new Date(28800000);(TDATE).setMonth(11);TDATE",
134                     UTCDateFromTime(SetMonth(28800000,11,0)),
135                     LocalDateFromTime(SetMonth(28800000,11,0)) );
136
137     addNewTestCase( "TDATE = new Date(28800000);(TDATE).setMonth(-11);TDATE",
138                     UTCDateFromTime(SetMonth(28800000,-11)),
139                     LocalDateFromTime(SetMonth(28800000,-11)) );
140
141     // 1900
142
143 //    addNewTestCase( "TDATE = new Date(); (TDATE).setMonth(11,31); TDATE;"
144 */
145
146 }
147 function addNewTestCase( DateString, UTCDate, LocalDate) {
148     DateCase = eval( DateString );
149
150     var item = testcases.length;
151
152 //    fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
153
154     testcases[item++] = new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
155     testcases[item++] = new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
156
157     testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
158     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
159     testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
160     testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
161     testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
162     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
163     testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
164     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
165
166     testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
167     testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
168     testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
169     testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
170     testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
171     testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
172     testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
173     testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
174
175     DateCase.toString = Object.prototype.toString;
176
177     testcases[item++] = new TestCase( SECTION,
178                                       DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
179                                       "[object Date]",
180                                       DateCase.toString() );
181 }
182 function MyDate() {
183     this.year = 0;
184     this.month = 0;
185     this.date = 0;
186     this.hours = 0;
187     this.minutes = 0;
188     this.seconds = 0;
189     this.ms = 0;
190 }
191 function LocalDateFromTime(t) {
192     t = LocalTime(t);
193     return ( MyDateFromTime(t) );
194 }
195 function UTCDateFromTime(t) {
196  return ( MyDateFromTime(t) );
197 }
198 function MyDateFromTime( t ) {
199     var d = new MyDate();
200     d.year = YearFromTime(t);
201     d.month = MonthFromTime(t);
202     d.date = DateFromTime(t);
203     d.hours = HourFromTime(t);
204     d.minutes = MinFromTime(t);
205     d.seconds = SecFromTime(t);
206     d.ms = msFromTime(t);
207
208     d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
209     d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
210     d.day = WeekDay( d.value );
211
212     return (d);
213 }
214 function SetMonth( t, mon, date ) {
215     var TIME = LocalTime(t);
216     var MONTH = Number( mon );
217     var DATE = ( date == void 0 ) ? DateFromTime(TIME) : Number( date );
218     var DAY = MakeDay( YearFromTime(TIME), MONTH, DATE );
219     return ( TimeClip (UTC(MakeDate( DAY, TimeWithinDay(TIME) ))) );
220 }