Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Date / 15.9.5.31-1.js
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
4  *
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/
9  *
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
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code, released
16  * March 31, 1998.
17  *
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.
22  *
23  * Contributor(s):
24  *
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.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 /**
41    File Name:          15.9.5.31-1.js
42
43    ECMA Section:      
44    15.9.5.31 Date.prototype.setUTCHours(hour [, min [, sec [, ms ]]] )
45
46    Description:
47
48    If min is not specified, this behaves as if min were specified with
49    the value getUTCMinutes( ).  If sec is not specified, this behaves
50    as if sec were specified with the value getUTCSeconds ( ).  If ms
51    is not specified, this behaves as if ms were specified with the
52    value getUTCMilliseconds( ).
53
54    1.Let t be this time value.
55    2.Call ToNumber(hour).
56    3.If min is not specified, compute MinFromTime(t);
57    otherwise, call ToNumber(min).
58    4.If sec is not specified, compute SecFromTime(t);
59    otherwise, call ToNumber(sec).
60    5.If ms is not specified, compute msFromTime(t);
61    otherwise, call ToNumber(ms).
62    6.Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
63    7.Compute MakeDate(Day(t), Result(6)).
64    8.Set the [[Value]] property of the this value to TimeClip(Result(7)).
65
66    1.Return the value of the [[Value]] property of the this value.
67    Author:             christine@netscape.com
68    Date:               12 november 1997
69 */
70 var SECTION = "15.9.5.31-1";
71 var VERSION = "ECMA_1";
72 startTest();
73
74 writeHeaderToLog(SECTION +
75                  " Date.prototype.setUTCHours(hour [, min [, sec [, ms ]]] )");
76
77 addNewTestCase( 0, 0, void 0, void 0, void 0,
78                 "TDATE = new Date(0);(TDATE).setUTCHours(0);TDATE",
79                 UTCDateFromTime(SetUTCHours(0,0,0,0)),
80                 LocalDateFromTime(SetUTCHours(0,0,0,0)) );
81
82 addNewTestCase( 28800000, 23, 59, 999, void 0,
83                 "TDATE = new Date(28800000);(TDATE).setUTCHours(23,59,999);TDATE",
84                 UTCDateFromTime(SetUTCHours(28800000,23,59,999)),
85                 LocalDateFromTime(SetUTCHours(28800000,23,59,999)) );
86
87 addNewTestCase( 28800000,999,999, void 0, void 0,
88                 "TDATE = new Date(28800000);(TDATE).setUTCHours(999,999);TDATE",
89                 UTCDateFromTime(SetUTCHours(28800000,999,999)),
90                 LocalDateFromTime(SetUTCHours(28800000,999,999)) );
91
92 addNewTestCase( 28800000, 999, void 0, void 0, void 0,
93                 "TDATE = new Date(28800000);(TDATE).setUTCHours(999);TDATE",
94                 UTCDateFromTime(SetUTCHours(28800000,999,0)),
95                 LocalDateFromTime(SetUTCHours(28800000,999,0)) );
96
97 addNewTestCase( 28800000, -8670, void 0, void 0, void 0,
98                 "TDATE = new Date(28800000);(TDATE).setUTCHours(-8670);TDATE",
99                 UTCDateFromTime(SetUTCHours(28800000,-8670)),
100                 LocalDateFromTime(SetUTCHours(28800000,-8670)) );
101
102 // modify hours to remove dst ambiguity
103 addNewTestCase( 946684800000, 1235567, void 0, void 0, void 0,
104                 "TDATE = new Date(946684800000);(TDATE).setUTCHours(1235567);TDATE",
105                 UTCDateFromTime(SetUTCHours(946684800000,1235567)),
106                 LocalDateFromTime(SetUTCHours(946684800000,1235567)) );
107
108 addNewTestCase( -2208988800000, 59, 999, void 0, void 0,
109                 "TDATE = new Date(-2208988800000);(TDATE).setUTCHours(59,999);TDATE",
110                 UTCDateFromTime(SetUTCHours(-2208988800000,59,999)),
111                 LocalDateFromTime(SetUTCHours(-2208988800000,59,999)) );
112
113 test();
114
115 function addNewTestCase( time, hours, min, sec, ms, DateString, UTCDate, LocalDate) {
116
117   DateCase = new Date(time);
118   if ( min == void 0 ) {
119     DateCase.setUTCHours( hours );
120   } else {
121     if ( sec == void 0 ) {
122       DateCase.setUTCHours( hours, min );
123     } else {
124       if ( ms == void 0 ) {
125         DateCase.setUTCHours( hours, min, sec );
126       } else {
127         DateCase.setUTCHours( hours, min, sec, ms );
128       }
129     }
130   }
131
132   new TestCase( SECTION, DateString+".getTime()",            UTCDate.value,
133                 DateCase.getTime() );
134   new TestCase( SECTION, DateString+".valueOf()",            UTCDate.value,
135                 DateCase.valueOf() );
136   new TestCase( SECTION, DateString+".getUTCFullYear()",     UTCDate.year,
137                 DateCase.getUTCFullYear() );
138   new TestCase( SECTION, DateString+".getUTCMonth()",        UTCDate.month,
139                 DateCase.getUTCMonth() );
140   new TestCase( SECTION, DateString+".getUTCDate()",         UTCDate.date,
141                 DateCase.getUTCDate() );
142   new TestCase( SECTION, DateString+".getUTCDay()",          UTCDate.day,
143                 DateCase.getUTCDay() );
144   new TestCase( SECTION, DateString+".getUTCHours()",        UTCDate.hours,
145                 DateCase.getUTCHours() );
146   new TestCase( SECTION, DateString+".getUTCMinutes()",      UTCDate.minutes,
147                 DateCase.getUTCMinutes() );
148   new TestCase( SECTION, DateString+".getUTCSeconds()",      UTCDate.seconds,
149                 DateCase.getUTCSeconds() );
150   new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms,
151                 DateCase.getUTCMilliseconds() );
152
153   new TestCase( SECTION, DateString+".getFullYear()",        LocalDate.year,
154                 DateCase.getFullYear() );
155   new TestCase( SECTION, DateString+".getMonth()",           LocalDate.month,
156                 DateCase.getMonth() );
157   new TestCase( SECTION, DateString+".getDate()",            LocalDate.date,
158                 DateCase.getDate() );
159   new TestCase( SECTION, DateString+".getDay()",             LocalDate.day,
160                 DateCase.getDay() );
161   new TestCase( SECTION, DateString+".getHours()",           LocalDate.hours,
162                 DateCase.getHours() );
163   new TestCase( SECTION, DateString+".getMinutes()",         LocalDate.minutes,
164                 DateCase.getMinutes() );
165   new TestCase( SECTION, DateString+".getSeconds()",         LocalDate.seconds,
166                 DateCase.getSeconds() );
167   new TestCase( SECTION, DateString+".getMilliseconds()",    LocalDate.ms,
168                 DateCase.getMilliseconds() );
169
170   DateCase.toString = Object.prototype.toString;
171
172   new TestCase( SECTION,
173                 DateString+".toString=Object.prototype.toString;" +
174                 DateString+".toString()",
175                 "[object Date]",
176                 DateCase.toString() );
177 }
178 function MyDate() {
179   this.year = 0;
180   this.month = 0;
181   this.date = 0;
182   this.hours = 0;
183   this.minutes = 0;
184   this.seconds = 0;
185   this.ms = 0;
186 }
187 function LocalDateFromTime(t) {
188   t = LocalTime(t);
189   return ( MyDateFromTime(t) );
190 }
191 function UTCDateFromTime(t) {
192   return ( MyDateFromTime(t) );
193 }
194 function MyDateFromTime( t ) {
195   var d = new MyDate();
196   d.year = YearFromTime(t);
197   d.month = MonthFromTime(t);
198   d.date = DateFromTime(t);
199   d.hours = HourFromTime(t);
200   d.minutes = MinFromTime(t);
201   d.seconds = SecFromTime(t);
202   d.ms = msFromTime(t);
203
204   d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
205   d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
206   d.day = WeekDay( d.value );
207
208   return (d);
209 }
210 function SetUTCHours( t, hour, min, sec, ms ) {
211   var TIME = t;
212   var HOUR = Number(hour);
213   var MIN =  ( min == void 0) ? MinFromTime(TIME) : Number(min);
214   var SEC  = ( sec == void 0) ? SecFromTime(TIME) : Number(sec);
215   var MS   = ( ms == void 0 ) ? msFromTime(TIME)  : Number(ms);
216   var RESULT6 = MakeTime( HOUR,
217                           MIN,
218                           SEC,
219                           MS );
220   return ( TimeClip(MakeDate(Day(TIME), RESULT6)) );
221 }