]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma/Date/15.9.5.27-1.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / 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/
5 *
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.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
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
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22 /**
23 File Name: 15.9.5.27-1.js
24 ECMA Section: 15.9.5.27 Date.prototype.setUTCSeconds(sec [,ms])
25 Description:
26
27 If ms is not specified, this behaves as if ms were specified with the
28 value getUTCMilliseconds( ).
29
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
33 ToNumber(ms)
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.
38
39 Author: christine@netscape.com
40 Date: 12 november 1997
41 */
42 var SECTION = "15.9.5.27-1";
43 var VERSION = "ECMA_1";
44 startTest();
45
46 writeHeaderToLog( SECTION + " Date.prototype.setUTCSeconds(sec [,ms] )");
47
48 getTestCases();
49 test();
50
51 function test() {
52 for ( tc=0; tc < testcases.length; tc++ ) {
53 testcases[tc].passed = writeTestCaseResult(
54 testcases[tc].expect,
55 testcases[tc].actual,
56 testcases[tc].description +" = "+
57 testcases[tc].actual );
58
59 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
60 }
61 stopTest();
62 return ( testcases );
63 }
64
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)) );
69
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)) );
74
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)) );
79
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)) );
84
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)) );
89
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)) );
94
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)) );
99 /*
100 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
101 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)),
102 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)) );
103
104 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456);TDATE",
105 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456)),
106 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456)) );
107
108 addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(-123456);TDATE",
109 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)),
110 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)) );
111
112 addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMilliseconds(-999);TDATE",
113 UTCDateFromTime(SetUTCMilliseconds(0,-999)),
114 LocalDateFromTime(SetUTCMilliseconds(0,-999)) );
115 */
116 }
117 function addNewTestCase( startTime, sec, ms, DateString, UTCDate, LocalDate) {
118 DateCase = new Date( startTime );
119 if ( ms == void 0) {
120 DateCase.setSeconds( sec );
121 } else {
122 DateCase.setSeconds( sec, ms );
123 }
124
125
126 var item = testcases.length;
127
128 // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
129
130 testcases[item++] = new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
131 testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
132
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() );
141
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() );
150
151 DateCase.toString = Object.prototype.toString;
152
153 testcases[item++] = new TestCase( SECTION,
154 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
155 "[object Date]",
156 DateCase.toString() );
157 }
158
159 function MyDate() {
160 this.year = 0;
161 this.month = 0;
162 this.date = 0;
163 this.hours = 0;
164 this.minutes = 0;
165 this.seconds = 0;
166 this.ms = 0;
167 }
168 function LocalDateFromTime(t) {
169 t = LocalTime(t);
170 return ( MyDateFromTime(t) );
171 }
172 function UTCDateFromTime(t) {
173 return ( MyDateFromTime(t) );
174 }
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);
184
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 );
188
189 return (d);
190 }
191
192 function SetUTCSeconds( t, s, m ) {
193 var TIME = t;
194 var SEC = Number(s);
195 var MS = ( m == void 0 ) ? msFromTime(TIME) : Number( m );
196 var RESULT4 = MakeTime( HourFromTime( TIME ),
197 MinFromTime( TIME ),
198 SEC,
199 MS );
200 return ( TimeClip(MakeDate(Day(TIME), RESULT4)) );
201 }
202