]>
git.saurik.com Git - apple/javascriptcore.git/blob - 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/
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.
11 * The Original Code is Mozilla Communicator client code, released March
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
23 File Name: 15.9.5.28-1.js
24 ECMA Section: 15.9.5.28 Date.prototype.setMinutes(min [, sec [, ms ]] )
26 If sec is not specified, this behaves as if sec were specified with the
29 If ms is not specified, this behaves as if ms were specified with the
30 value getMilliseconds( ).
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.
41 Author: christine@netscape.com
42 Date: 12 november 1997
44 var SECTION
= "15.9.5.28-1";
45 var VERSION
= "ECMA_1";
48 writeHeaderToLog( SECTION
+ " Date.prototype.setMinutes(sec [,ms] )");
54 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
55 testcases
[tc
].passed
= writeTestCaseResult(
58 testcases
[tc
].description
+" = "+
59 testcases
[tc
].actual
);
61 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
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)) );
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)) );
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)) );
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)) );
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)) );
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)) );
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)) );
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)) );
108 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
109 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)),
110 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)) );
112 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456);TDATE",
113 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456)),
114 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456)) );
116 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(-123456);TDATE",
117 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)),
118 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)) );
120 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMilliseconds(-999);TDATE",
121 UTCDateFromTime(SetUTCMilliseconds(0,-999)),
122 LocalDateFromTime(SetUTCMilliseconds(0,-999)) );
126 function addNewTestCase( time
, min
, sec
, ms
, DateString
, UTCDate
, LocalDate
) {
127 DateCase
= new Date( time
);
129 if ( sec
== void 0 ) {
130 DateCase
.setMinutes( min
);
132 if ( ms
== void 0 ) {
133 DateCase
.setMinutes( min
, sec
);
135 DateCase
.setMinutes( min
, sec
, ms
);
140 var item
= testcases
.length
;
142 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
144 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", UTCDate
.value
, DateCase
.getTime() );
145 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", UTCDate
.value
, DateCase
.valueOf() );
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() );
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() );
165 DateCase
.toString
= Object
.prototype.toString
;
167 testcases
[item
++] = new TestCase( SECTION
,
168 DateString
+".toString=Object.prototype.toString;"+DateString
+".toString()",
170 DateCase
.toString() );
182 function LocalDateFromTime(t
) {
184 return ( MyDateFromTime(t
) );
186 function UTCDateFromTime(t
) {
187 return ( MyDateFromTime(t
) );
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
);
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
);
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
),
215 return ( TimeClip(UTC( MakeDate(Day(TIME
),RESULT5
))) );