]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.5.23-18.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.23-1.js
24 ECMA Section: 15.9.5.23 Date.prototype.setTime(time)
27 1. If the this value is not a Date object, generate a runtime error.
28 2. Call ToNumber(time).
29 3. Call TimeClip(Result(1)).
30 4. Set the [[Value]] property of the this value to Result(2).
31 5. Return the value of the [[Value]] property of the this value.
33 Author: christine@netscape.com
34 Date: 12 november 1997
37 var SECTION
= "15.9.5.23-1";
38 var VERSION
= "ECMA_1";
40 var TITLE
= "Date.prototype.setTime()";
42 writeHeaderToLog( SECTION
+ " Date.prototype.setTime(time)");
44 var testcases
= new Array();
48 function getTestCases() {
50 addTestCase( now
, String( TIME_2000
) );
53 function addTestCase( startTime
, setTime
) {
54 if ( startTime
== "now" ) {
55 DateCase
= new Date();
57 DateCase
= new Date( startTime
);
60 DateCase
.setTime( setTime
);
61 var DateString
= "var d = new Date("+startTime
+"); d.setTime("+setTime
+"); d" ;
62 var UTCDate
= UTCDateFromTime ( Number(setTime
) );
63 var LocalDate
= LocalDateFromTime( Number(setTime
) );
64 var item
= testcases
.length
;
66 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
68 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", UTCDate
.value
, DateCase
.getTime() );
69 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", UTCDate
.value
, DateCase
.valueOf() );
71 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", UTCDate
.year
, DateCase
.getUTCFullYear() );
72 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", UTCDate
.month
, DateCase
.getUTCMonth() );
73 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", UTCDate
.date
, DateCase
.getUTCDate() );
74 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDay()", UTCDate
.day
, DateCase
.getUTCDay() );
75 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", UTCDate
.hours
, DateCase
.getUTCHours() );
76 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", UTCDate
.minutes
, DateCase
.getUTCMinutes() );
77 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", UTCDate
.seconds
, DateCase
.getUTCSeconds() );
78 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", UTCDate
.ms
, DateCase
.getUTCMilliseconds() );
80 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", LocalDate
.year
, DateCase
.getFullYear() );
81 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", LocalDate
.month
, DateCase
.getMonth() );
82 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", LocalDate
.date
, DateCase
.getDate() );
83 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDay()", LocalDate
.day
, DateCase
.getDay() );
84 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", LocalDate
.hours
, DateCase
.getHours() );
85 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", LocalDate
.minutes
, DateCase
.getMinutes() );
86 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", LocalDate
.seconds
, DateCase
.getSeconds() );
87 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", LocalDate
.ms
, DateCase
.getMilliseconds() );
89 DateCase
.toString
= Object
.prototype.toString
;
91 testcases
[item
++] = new TestCase( SECTION
,
92 DateString
+".toString=Object.prototype.toString;"+DateString
+".toString()",
94 DateCase
.toString() );
105 function LocalDateFromTime(t
) {
107 return ( MyDateFromTime(t
) );
109 function UTCDateFromTime(t
) {
110 return ( MyDateFromTime(t
) );
112 function MyDateFromTime( t
) {
113 var d
= new MyDate();
114 d
.year
= YearFromTime(t
);
115 d
.month
= MonthFromTime(t
);
116 d
.date
= DateFromTime(t
);
117 d
.hours
= HourFromTime(t
);
118 d
.minutes
= MinFromTime(t
);
119 d
.seconds
= SecFromTime(t
);
120 d
.ms
= msFromTime(t
);
121 d
.time
= MakeTime( d
.hours
, d
.minutes
, d
.seconds
, d
.ms
);
122 d
.value
= TimeClip( MakeDate( MakeDay( d
.year
, d
.month
, d
.date
), d
.time
) );
123 d
.day
= WeekDay( d
.value
);
128 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
129 testcases
[tc
].passed
= writeTestCaseResult(
130 testcases
[tc
].expect
,
131 testcases
[tc
].actual
,
132 testcases
[tc
].description
+" = "+
133 testcases
[tc
].actual
);
135 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
138 return ( testcases
);