]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.5.24-6.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.24-1.js
24 ECMA Section: 15.9.5.24 Date.prototype.setTime(time)
26 1. If the this value is not a Date object, generate a runtime error.
27 2. Call ToNumber(time).
28 3. Call TimeClip(Result(1)).
29 4. Set the [[Value]] property of the this value to Result(2).
30 5. Return the value of the [[Value]] property of the this value.
31 Author: christine@netscape.com
32 Date: 12 november 1997
35 var TITLE
= "Date.prototype.setTime"
36 var SECTION
= "15.9.5.24-1";
37 var VERSION
= "ECMA_1";
40 writeHeaderToLog( SECTION
+ " Date.prototype.setMilliseconds(ms)");
42 var testcases
= new Array();
47 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
48 testcases
[tc
].passed
= writeTestCaseResult(
51 testcases
[tc
].description
+" = "+
52 testcases
[tc
].actual
);
54 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
60 function getTestCases() {
62 addTestCase( 0, "-2208988800000" );
64 addTestCase( 0, "-86400000" );
65 addTestCase( 0, "946684800000" );
68 function addTestCase( startms
, newms
) {
70 var DateCase
= new Date( startms
);
71 DateCase
.setMilliseconds( newms
);
72 var DateString
= "var date = new Date("+ startms
+"); date.setMilliseconds("+ newms
+"); date";
73 var UTCDate
= UTCDateFromTime( Number(newms
) );
74 var LocalDate
= LocalDateFromTime( Number(newms
) );
76 var item
= testcases
.length
;
78 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
80 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", UTCDate
.value
, DateCase
.getTime() );
81 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", UTCDate
.value
, DateCase
.valueOf() );
83 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", UTCDate
.year
, DateCase
.getUTCFullYear() );
84 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", UTCDate
.month
, DateCase
.getUTCMonth() );
85 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", UTCDate
.date
, DateCase
.getUTCDate() );
86 // testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
87 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", UTCDate
.hours
, DateCase
.getUTCHours() );
88 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", UTCDate
.minutes
,DateCase
.getUTCMinutes() );
89 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", UTCDate
.seconds
,DateCase
.getUTCSeconds() );
90 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", UTCDate
.ms
, DateCase
.getUTCMilliseconds() );
92 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", LocalDate
.year
, DateCase
.getFullYear() );
93 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", LocalDate
.month
, DateCase
.getMonth() );
94 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", LocalDate
.date
, DateCase
.getDate() );
95 // testcases[item++] = new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
96 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", LocalDate
.hours
, DateCase
.getHours() );
97 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", LocalDate
.minutes
, DateCase
.getMinutes() );
98 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", LocalDate
.seconds
, DateCase
.getSeconds() );
99 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", LocalDate
.ms
, DateCase
.getMilliseconds() );
101 DateCase
.toString
= Object
.prototype.toString
;
103 testcases
[item
++] = new TestCase( SECTION
,
104 DateString
+".toString=Object.prototype.toString;"+DateString
+".toString()",
106 DateCase
.toString() );
118 function LocalDateFromTime(t
) {
120 return ( MyDateFromTime(t
) );
122 function UTCDateFromTime(t
) {
123 return ( MyDateFromTime(t
) );
125 function MyDateFromTime( t
) {
126 var d
= new MyDate();
127 d
.year
= YearFromTime(t
);
128 d
.month
= MonthFromTime(t
);
129 d
.date
= DateFromTime(t
);
130 d
.hours
= HourFromTime(t
);
131 d
.minutes
= MinFromTime(t
);
132 d
.seconds
= SecFromTime(t
);
133 d
.ms
= msFromTime(t
);
135 d
.time
= MakeTime( d
.hours
, d
.minutes
, d
.seconds
, d
.ms
);
136 d
.value
= TimeClip( MakeDate( MakeDay( d
.year
, d
.month
, d
.date
), d
.time
) );
137 d
.day
= WeekDay( d
.value
);