1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
41 File Name: 15.9.5.28-1.js
42 ECMA Section: 15.9.5.28 Date.prototype.setMinutes(min [, sec [, ms ]] )
44 If sec is not specified, this behaves as if sec were specified with the
47 If ms is not specified, this behaves as if ms were specified with the
48 value getMilliseconds( ).
50 1. Let t be the result of LocalTime(this time value).
51 2. Call ToNumber(min).
52 3. If sec is not specified, compute SecFromTime(t); otherwise, call ToNumber(sec).
53 4. If ms is not specified, compute msFromTime(t); otherwise, call ToNumber(ms).
54 5. Compute MakeTime(HourFromTime(t), Result(2), Result(3), Result(4)).
55 6. Compute UTC(MakeDate(Day(t), Result(5))).
56 7. Set the [[Value]] property of the this value to TimeClip(Result(6)).
57 8. Return the value of the [[Value]] property of the this value.
59 Author: christine@netscape.com
60 Date: 12 november 1997
62 var SECTION = "15.9.5.28-1";
63 var VERSION = "ECMA_1";
66 writeHeaderToLog( SECTION + " Date.prototype.setMinutes(sec [,ms] )");
68 addNewTestCase( 0, 0, void 0, void 0,
69 "TDATE = new Date(0);(TDATE).setMinutes(0);TDATE",
70 UTCDateFromTime(SetMinutes(0,0,0,0)),
71 LocalDateFromTime(SetMinutes(0,0,0,0)) );
73 addNewTestCase( 28800000, 59, 59, void 0,
74 "TDATE = new Date(28800000);(TDATE).setMinutes(59,59);TDATE",
75 UTCDateFromTime(SetMinutes(28800000,59,59)),
76 LocalDateFromTime(SetMinutes(28800000,59,59)) );
78 addNewTestCase( 28800000, 59, 59, 999,
79 "TDATE = new Date(28800000);(TDATE).setMinutes(59,59,999);TDATE",
80 UTCDateFromTime(SetMinutes(28800000,59,59,999)),
81 LocalDateFromTime(SetMinutes(28800000,59,59,999)) );
83 addNewTestCase( 28800000, 59, void 0, void 0,
84 "TDATE = new Date(28800000);(TDATE).setMinutes(59);TDATE",
85 UTCDateFromTime(SetMinutes(28800000,59,0)),
86 LocalDateFromTime(SetMinutes(28800000,59,0)) );
88 addNewTestCase( 28800000, -480, void 0, void 0,
89 "TDATE = new Date(28800000);(TDATE).setMinutes(-480);TDATE",
90 UTCDateFromTime(SetMinutes(28800000,-480)),
91 LocalDateFromTime(SetMinutes(28800000,-480)) );
93 addNewTestCase( 946684800000, 1234567, void 0, void 0,
94 "TDATE = new Date(946684800000);(TDATE).setMinutes(1234567);TDATE",
95 UTCDateFromTime(SetMinutes(946684800000,1234567)),
96 LocalDateFromTime(SetMinutes(946684800000,1234567)) );
98 addNewTestCase( -2208988800000,59, 59, void 0,
99 "TDATE = new Date(-2208988800000);(TDATE).setMinutes(59,59);TDATE",
100 UTCDateFromTime(SetMinutes(-2208988800000,59,59)),
101 LocalDateFromTime(SetMinutes(-2208988800000,59,59)) );
103 addNewTestCase( -2208988800000, 59, 59, 999,
104 "TDATE = new Date(-2208988800000);(TDATE).setMinutes(59,59,999);TDATE",
105 UTCDateFromTime(SetMinutes(-2208988800000,59,59,999)),
106 LocalDateFromTime(SetMinutes(-2208988800000,59,59,999)) );
110 function addNewTestCase( time, min, sec, ms, DateString, UTCDate, LocalDate) {
111 DateCase = new Date( time );
113 if ( sec == void 0 ) {
114 DateCase.setMinutes( min );
116 if ( ms == void 0 ) {
117 DateCase.setMinutes( min, sec );
119 DateCase.setMinutes( min, sec, ms );
123 new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
124 new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
126 new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
127 new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
128 new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
130 new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
131 new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
132 new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
133 new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
135 new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
136 new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
137 new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
139 new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
140 new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
141 new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
142 new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
144 DateCase.toString = Object.prototype.toString;
146 new TestCase( SECTION,
147 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
149 DateCase.toString() );
161 function LocalDateFromTime(t) {
163 return ( MyDateFromTime(t) );
165 function UTCDateFromTime(t) {
166 return ( MyDateFromTime(t) );
168 function MyDateFromTime( t ) {
169 var d = new MyDate();
170 d.year = YearFromTime(t);
171 d.month = MonthFromTime(t);
172 d.date = DateFromTime(t);
173 d.hours = HourFromTime(t);
174 d.minutes = MinFromTime(t);
175 d.seconds = SecFromTime(t);
176 d.ms = msFromTime(t);
178 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
179 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
180 d.day = WeekDay( d.value );
185 function SetMinutes( t, min, sec, ms ) {
186 var TIME = LocalTime(t);
187 var MIN = Number(min);
188 var SEC = ( sec == void 0) ? SecFromTime(TIME) : Number(sec);
189 var MS = ( ms == void 0 ) ? msFromTime(TIME) : Number(ms);
190 var RESULT5 = MakeTime( HourFromTime( TIME ),
194 return ( TimeClip(UTC( MakeDate(Day(TIME),RESULT5))) );