]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
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.29-1.js | |
24 | ECMA Section: 15.9.5.29 Date.prototype.setUTCMinutes(min [, sec [, ms ]] ) | |
25 | Description: | |
26 | If sec is not specified, this behaves as if sec were specified with the | |
27 | value getUTCSeconds ( ). | |
28 | ||
29 | If ms is not specified, this behaves as if ms were specified with the value | |
30 | getUTCMilliseconds( ). | |
31 | ||
32 | 1. Let t be this time value. | |
33 | 2. Call ToNumber(min). | |
34 | 3. If sec is not specified, compute SecFromTime(t); otherwise, call | |
35 | ToNumber(sec). | |
36 | 4. If ms is not specified, compute msFromTime(t); otherwise, call | |
37 | ToNumber(ms). | |
38 | 5. Compute MakeTime(HourFromTime(t), Result(2), Result(3), Result(4)). | |
39 | 6. Compute MakeDate(Day(t), Result(5)). | |
40 | 7. Set the [[Value]] property of the this value to TimeClip(Result(6)). | |
41 | 8. Return the value of the [[Value]] property of the this value. | |
42 | ||
43 | Author: christine@netscape.com | |
44 | Date: 12 november 1997 | |
45 | */ | |
46 | var SECTION = "15.9.5.29-1"; | |
47 | var VERSION = "ECMA_1"; | |
48 | startTest(); | |
49 | ||
50 | writeHeaderToLog( SECTION + " Date.prototype.setUTCMinutes( min [, sec, ms] )"); | |
51 | ||
52 | getTestCases(); | |
53 | test(); | |
54 | ||
55 | function test() { | |
56 | for ( tc=0; tc < testcases.length; tc++ ) { | |
57 | testcases[tc].passed = writeTestCaseResult( | |
58 | testcases[tc].expect, | |
59 | testcases[tc].actual, | |
60 | testcases[tc].description +" = "+ | |
61 | testcases[tc].actual ); | |
62 | ||
63 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
64 | } | |
65 | stopTest(); | |
66 | return ( testcases ); | |
67 | } | |
68 | ||
69 | function getTestCases() { | |
70 | addNewTestCase( 0, 0, void 0, void 0, | |
71 | "TDATE = new Date(0);(TDATE).setUTCMinutes(0);TDATE", | |
72 | UTCDateFromTime(SetUTCMinutes(0,0,0,0)), | |
73 | LocalDateFromTime(SetUTCMinutes(0,0,0,0)) ); | |
74 | ||
75 | addNewTestCase( 28800000, 59, 59, void 0, | |
76 | "TDATE = new Date(28800000);(TDATE).setUTCMinutes(59,59);TDATE", | |
77 | UTCDateFromTime(SetUTCMinutes(28800000,59,59)), | |
78 | LocalDateFromTime(SetUTCMinutes(28800000,59,59)) ); | |
79 | ||
80 | addNewTestCase( 28800000, 59, 59, 999, | |
81 | "TDATE = new Date(28800000);(TDATE).setUTCMinutes(59,59,999);TDATE", | |
82 | UTCDateFromTime(SetUTCMinutes(28800000,59,59,999)), | |
83 | LocalDateFromTime(SetUTCMinutes(28800000,59,59,999)) ); | |
84 | ||
85 | addNewTestCase( 28800000, 59, void 0, void 0, | |
86 | "TDATE = new Date(28800000);(TDATE).setUTCMinutes(59);TDATE", | |
87 | UTCDateFromTime(SetUTCMinutes(28800000,59)), | |
88 | LocalDateFromTime(SetUTCMinutes(28800000,59)) ); | |
89 | ||
90 | addNewTestCase( 28800000, -480, 0, 0, | |
91 | "TDATE = new Date(28800000);(TDATE).setUTCMinutes(-480);TDATE", | |
92 | UTCDateFromTime(SetUTCMinutes(28800000,-480)), | |
93 | LocalDateFromTime(SetUTCMinutes(28800000,-480)) ); | |
94 | ||
95 | addNewTestCase( 946684800000, 1234567, void 0, void 0, | |
96 | "TDATE = new Date(946684800000);(TDATE).setUTCMinutes(1234567);TDATE", | |
97 | UTCDateFromTime(SetUTCMinutes(946684800000,1234567)), | |
98 | LocalDateFromTime(SetUTCMinutes(946684800000,1234567)) ); | |
99 | ||
100 | addNewTestCase( -2208988800000, 59, 999, void 0, | |
101 | "TDATE = new Date(-2208988800000);(TDATE).setUTCMinutes(59,999);TDATE", | |
102 | UTCDateFromTime(SetUTCMinutes(-2208988800000,59,999)), | |
103 | LocalDateFromTime(SetUTCMinutes(-2208988800000,59,999)) ); | |
104 | /* | |
105 | addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456789);TDATE", | |
106 | UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)), | |
107 | LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)) ); | |
108 | ||
109 | addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456);TDATE", | |
110 | UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456)), | |
111 | LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456)) ); | |
112 | ||
113 | addNewTestCase( "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(-123456);TDATE", | |
114 | UTCDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)), | |
115 | LocalDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)) ); | |
116 | ||
117 | addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCMilliseconds(-999);TDATE", | |
118 | UTCDateFromTime(SetUTCMilliseconds(0,-999)), | |
119 | LocalDateFromTime(SetUTCMilliseconds(0,-999)) ); | |
120 | */ | |
121 | ||
122 | } | |
123 | function addNewTestCase( time, min, sec, ms, DateString, UTCDate, LocalDate) { | |
124 | var DateCase = new Date( time ); | |
125 | ||
126 | if ( sec == void 0 ) { | |
127 | DateCase.setUTCMinutes( min ); | |
128 | } else { | |
129 | if ( ms == void 0 ) { | |
130 | DateCase.setUTCMinutes( min, sec ); | |
131 | } else { | |
132 | DateCase.setUTCMinutes( min, sec, ms ); | |
133 | } | |
134 | } | |
135 | ||
136 | var item = testcases.length; | |
137 | ||
138 | // fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year; | |
139 | ||
140 | testcases[item++] = new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); | |
141 | testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); | |
142 | ||
143 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); | |
144 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); | |
145 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); | |
146 | // testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() ); | |
147 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); | |
148 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); | |
149 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); | |
150 | testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); | |
151 | ||
152 | testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); | |
153 | testcases[item++] = new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); | |
154 | testcases[item++] = new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); | |
155 | // testcases[item++] = new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() ); | |
156 | testcases[item++] = new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); | |
157 | testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); | |
158 | testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); | |
159 | testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); | |
160 | ||
161 | DateCase.toString = Object.prototype.toString; | |
162 | ||
163 | testcases[item++] = new TestCase( SECTION, | |
164 | DateString+".toString=Object.prototype.toString;"+DateString+".toString()", | |
165 | "[object Date]", | |
166 | DateCase.toString() ); | |
167 | } | |
168 | function MyDate() { | |
169 | this.year = 0; | |
170 | this.month = 0; | |
171 | this.date = 0; | |
172 | this.hours = 0; | |
173 | this.minutes = 0; | |
174 | this.seconds = 0; | |
175 | this.ms = 0; | |
176 | } | |
177 | function LocalDateFromTime(t) { | |
178 | t = LocalTime(t); | |
179 | return ( MyDateFromTime(t) ); | |
180 | } | |
181 | function UTCDateFromTime(t) { | |
182 | return ( MyDateFromTime(t) ); | |
183 | } | |
184 | function MyDateFromTime( t ) { | |
185 | var d = new MyDate(); | |
186 | d.year = YearFromTime(t); | |
187 | d.month = MonthFromTime(t); | |
188 | d.date = DateFromTime(t); | |
189 | d.hours = HourFromTime(t); | |
190 | d.minutes = MinFromTime(t); | |
191 | d.seconds = SecFromTime(t); | |
192 | d.ms = msFromTime(t); | |
193 | ||
194 | d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); | |
195 | d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); | |
196 | d.day = WeekDay( d.value ); | |
197 | ||
198 | return (d); | |
199 | } | |
200 | function SetUTCMinutes( t, min, sec, ms ) { | |
201 | var TIME = t; | |
202 | var MIN = Number(min); | |
203 | var SEC = ( sec == void 0) ? SecFromTime(TIME) : Number(sec); | |
204 | var MS = ( ms == void 0 ) ? msFromTime(TIME) : Number(ms); | |
205 | var RESULT5 = MakeTime( HourFromTime( TIME ), | |
206 | MIN, | |
207 | SEC, | |
208 | MS ); | |
209 | return ( TimeClip(MakeDate(Day(TIME),RESULT5)) ); | |
210 | } |