]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.5.33-1.js
017d43e92e3d123bba3be7b313be210952181d09
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.33-1.js
24 ECMA Section: 15.9.5.33 Date.prototype.setUTCDate(date)
26 1. Let t be this time value.
27 2. Call ToNumber(date).
28 3. Compute MakeDay(YearFromTime(t), MonthFromTime(t), Result(2)).
29 4. Compute MakeDate(Result(3), TimeWithinDay(t)).
30 5. Set the [[Value]] property of the this value to TimeClip(Result(4)).
31 6. Return the value of the [[Value]] property of the this value.
33 Author: christine@netscape.com
34 Date: 12 november 1997
36 var SECTION
= "15.9.5.33-1";
37 var VERSION
= "ECMA_1";
40 writeHeaderToLog( SECTION
+ " Date.prototype.setUTCDate(date) ");
46 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
47 testcases
[tc
].passed
= writeTestCaseResult(
50 testcases
[tc
].description
+" = "+
51 testcases
[tc
].actual
);
53 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
59 function getTestCases() {
60 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCDate(31);TDATE",
61 UTCDateFromTime(SetUTCDate(0,31)),
62 LocalDateFromTime(SetUTCDate(0,31)) );
64 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCDate(1);TDATE",
65 UTCDateFromTime(SetUTCDate(0,1)),
66 LocalDateFromTime(SetUTCDate(0,1)) );
68 addNewTestCase( "TDATE = new Date(86400000);(TDATE).setUTCDate(1);TDATE",
69 UTCDateFromTime(SetUTCDate(86400000,1)),
70 LocalDateFromTime(SetUTCDate(86400000,1)) );
72 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1972);TDATE",
73 UTCDateFromTime(SetUTCFullYear(0,1972)),
74 LocalDateFromTime(SetUTCFullYear(0,1972)) );
76 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1968);TDATE",
77 UTCDateFromTime(SetUTCFullYear(0,1968)),
78 LocalDateFromTime(SetUTCFullYear(0,1968)) );
80 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1969);TDATE",
81 UTCDateFromTime(SetUTCFullYear(0,1969)),
82 LocalDateFromTime(SetUTCFullYear(0,1969)) );
85 function addNewTestCase( DateString
, UTCDate
, LocalDate
) {
86 DateCase
= eval( DateString
);
88 var item
= testcases
.length
;
90 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", UTCDate
.value
, DateCase
.getTime() );
91 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", UTCDate
.value
, DateCase
.valueOf() );
93 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", UTCDate
.year
, DateCase
.getUTCFullYear() );
94 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", UTCDate
.month
, DateCase
.getUTCMonth() );
95 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", UTCDate
.date
, DateCase
.getUTCDate() );
96 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDay()", UTCDate
.day
, DateCase
.getUTCDay() );
97 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", UTCDate
.hours
, DateCase
.getUTCHours() );
98 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", UTCDate
.minutes
,DateCase
.getUTCMinutes() );
99 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", UTCDate
.seconds
,DateCase
.getUTCSeconds() );
100 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", UTCDate
.ms
, DateCase
.getUTCMilliseconds() );
102 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", LocalDate
.year
, DateCase
.getFullYear() );
103 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", LocalDate
.month
, DateCase
.getMonth() );
104 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", LocalDate
.date
, DateCase
.getDate() );
105 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDay()", LocalDate
.day
, DateCase
.getDay() );
106 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", LocalDate
.hours
, DateCase
.getHours() );
107 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", LocalDate
.minutes
, DateCase
.getMinutes() );
108 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", LocalDate
.seconds
, DateCase
.getSeconds() );
109 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", LocalDate
.ms
, DateCase
.getMilliseconds() );
111 DateCase
.toString
= Object
.prototype.toString
;
113 testcases
[item
++] = new TestCase( SECTION
,
114 DateString
+".toString=Object.prototype.toString;"+DateString
+".toString()",
116 DateCase
.toString() );
127 function LocalDateFromTime(t
) {
129 return ( MyDateFromTime(t
) );
131 function UTCDateFromTime(t
) {
132 return ( MyDateFromTime(t
) );
134 function MyDateFromTime( t
) {
135 var d
= new MyDate();
136 d
.year
= YearFromTime(t
);
137 d
.month
= MonthFromTime(t
);
138 d
.date
= DateFromTime(t
);
139 d
.hours
= HourFromTime(t
);
140 d
.minutes
= MinFromTime(t
);
141 d
.seconds
= SecFromTime(t
);
142 d
.ms
= msFromTime(t
);
144 d
.time
= MakeTime( d
.hours
, d
.minutes
, d
.seconds
, d
.ms
);
145 d
.value
= TimeClip( MakeDate( MakeDay( d
.year
, d
.month
, d
.date
), d
.time
) );
146 d
.day
= WeekDay( d
.value
);
150 function SetUTCDate( t
, date
) {
152 var DATE
= Number( date
);
153 var RESULT3
= MakeDay(YearFromTime(T
), MonthFromTime(T
), DATE
);
154 return ( TimeClip(MakeDate(RESULT3
, TimeWithinDay(t
))) );