]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.5.27-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.27-1.js
24 ECMA Section: 15.9.5.27 Date.prototype.setUTCSeconds(sec [,ms])
27 If ms is not specified, this behaves as if ms were specified with the
28 value getUTCMilliseconds( ).
30 1. Let t be this time value.
31 2. Call ToNumber(sec).
32 3. If ms is not specified, compute msFromTime(t); otherwise, call
34 4. Compute MakeTime(HourFromTime(t), MinFromTime(t), Result(2), Result(3))
35 5. Compute MakeDate(Day(t), Result(4)).
36 6. Set the [[Value]] property of the this value to TimeClip(Result(5)).
37 7. Return the value of the [[Value]] property of the this value.
39 Author: christine@netscape.com
40 Date: 12 november 1997
42 var SECTION
= "15.9.5.27-1";
43 var VERSION
= "ECMA_1";
46 writeHeaderToLog( SECTION
+ " Date.prototype.setUTCSeconds(sec [,ms] )");
52 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
53 testcases
[tc
].passed
= writeTestCaseResult(
56 testcases
[tc
].description
+" = "+
57 testcases
[tc
].actual
);
59 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
65 function getTestCases() {
66 addNewTestCase( 0, 0, 0, "TDATE = new Date(0);(TDATE).setUTCSeconds(0,0);TDATE",
67 UTCDateFromTime(SetUTCSeconds(0,0,0)),
68 LocalDateFromTime(SetUTCSeconds(0,0,0)) );
70 addNewTestCase( 28800000,59,999,
71 "TDATE = new Date(28800000);(TDATE).setUTCSeconds(59,999);TDATE",
72 UTCDateFromTime(SetUTCSeconds(28800000,59,999)),
73 LocalDateFromTime(SetUTCSeconds(28800000,59,999)) );
75 addNewTestCase( 28800000,999,999,
76 "TDATE = new Date(28800000);(TDATE).setUTCSeconds(999,999);TDATE",
77 UTCDateFromTime(SetUTCSeconds(28800000,999,999)),
78 LocalDateFromTime(SetUTCSeconds(28800000,999,999)) );
80 addNewTestCase( 28800000, 999, void 0,
81 "TDATE = new Date(28800000);(TDATE).setUTCSeconds(999);TDATE",
82 UTCDateFromTime(SetUTCSeconds(28800000,999,0)),
83 LocalDateFromTime(SetUTCSeconds(28800000,999,0)) );
85 addNewTestCase( 28800000, -28800, void 0,
86 "TDATE = new Date(28800000);(TDATE).setUTCSeconds(-28800);TDATE",
87 UTCDateFromTime(SetUTCSeconds(28800000,-28800)),
88 LocalDateFromTime(SetUTCSeconds(28800000,-28800)) );
90 addNewTestCase( 946684800000, 1234567, void 0,
91 "TDATE = new Date(946684800000);(TDATE).setUTCSeconds(1234567);TDATE",
92 UTCDateFromTime(SetUTCSeconds(946684800000,1234567)),
93 LocalDateFromTime(SetUTCSeconds(946684800000,1234567)) );
95 addNewTestCase( -2208988800000,59,999,
96 "TDATE = new Date(-2208988800000);(TDATE).setUTCSeconds(59,999);TDATE",
97 UTCDateFromTime(SetUTCSeconds(-2208988800000,59,999)),
98 LocalDateFromTime(SetUTCSeconds(-2208988800000,59,999)) );
100 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
101 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)),
102 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)) );
104 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456);TDATE",
105 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456)),
106 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456)) );
108 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(-123456);TDATE",
109 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)),
110 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)) );
112 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMilliseconds(-999);TDATE",
113 UTCDateFromTime(SetUTCMilliseconds(0,-999)),
114 LocalDateFromTime(SetUTCMilliseconds(0,-999)) );
117 function addNewTestCase( startTime
, sec
, ms
, DateString
, UTCDate
, LocalDate
) {
118 DateCase
= new Date( startTime
);
120 DateCase
.setSeconds( sec
);
122 DateCase
.setSeconds( sec
, ms
);
126 var item
= testcases
.length
;
128 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
130 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getTime()", UTCDate
.value
, DateCase
.getTime() );
131 testcases
[item
++] = new TestCase( SECTION
, DateString
+".valueOf()", UTCDate
.value
, DateCase
.valueOf() );
133 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCFullYear()", UTCDate
.year
, DateCase
.getUTCFullYear() );
134 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMonth()", UTCDate
.month
, DateCase
.getUTCMonth() );
135 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCDate()", UTCDate
.date
, DateCase
.getUTCDate() );
136 // testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
137 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCHours()", UTCDate
.hours
, DateCase
.getUTCHours() );
138 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMinutes()", UTCDate
.minutes
,DateCase
.getUTCMinutes() );
139 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCSeconds()", UTCDate
.seconds
,DateCase
.getUTCSeconds() );
140 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getUTCMilliseconds()", UTCDate
.ms
, DateCase
.getUTCMilliseconds() );
142 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getFullYear()", LocalDate
.year
, DateCase
.getFullYear() );
143 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMonth()", LocalDate
.month
, DateCase
.getMonth() );
144 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getDate()", LocalDate
.date
, DateCase
.getDate() );
145 // testcases[item++] = new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
146 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getHours()", LocalDate
.hours
, DateCase
.getHours() );
147 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMinutes()", LocalDate
.minutes
, DateCase
.getMinutes() );
148 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getSeconds()", LocalDate
.seconds
, DateCase
.getSeconds() );
149 testcases
[item
++] = new TestCase( SECTION
, DateString
+".getMilliseconds()", LocalDate
.ms
, DateCase
.getMilliseconds() );
151 DateCase
.toString
= Object
.prototype.toString
;
153 testcases
[item
++] = new TestCase( SECTION
,
154 DateString
+".toString=Object.prototype.toString;"+DateString
+".toString()",
156 DateCase
.toString() );
168 function LocalDateFromTime(t
) {
170 return ( MyDateFromTime(t
) );
172 function UTCDateFromTime(t
) {
173 return ( MyDateFromTime(t
) );
175 function MyDateFromTime( t
) {
176 var d
= new MyDate();
177 d
.year
= YearFromTime(t
);
178 d
.month
= MonthFromTime(t
);
179 d
.date
= DateFromTime(t
);
180 d
.hours
= HourFromTime(t
);
181 d
.minutes
= MinFromTime(t
);
182 d
.seconds
= SecFromTime(t
);
183 d
.ms
= msFromTime(t
);
185 d
.time
= MakeTime( d
.hours
, d
.minutes
, d
.seconds
, d
.ms
);
186 d
.value
= TimeClip( MakeDate( MakeDay( d
.year
, d
.month
, d
.date
), d
.time
) );
187 d
.day
= WeekDay( d
.value
);
192 function SetUTCSeconds( t
, s
, m
) {
195 var MS
= ( m
== void 0 ) ? msFromTime(TIME
) : Number( m
);
196 var RESULT4
= MakeTime( HourFromTime( TIME
),
200 return ( TimeClip(MakeDate(Day(TIME
), RESULT4
)) );