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