Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Date / 15.9.5.25-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.25-1.js
42    ECMA Section:       15.9.5.25 Date.prototype.setUTCMilliseconds(ms)
43    Description:
44    1.  Let t be this time value.
45    2.  Call ToNumber(ms).
46    3.  Compute MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), Result(2)).
47    4.  Compute MakeDate(Day(t), Result(3)).
48    5.  Set the [[Value]] property of the this value to TimeClip(Result(4)).
49    6.  Return the value of the [[Value]] property of the this value.
50    Author:             christine@netscape.com
51    Date:               12 november 1997
52 */
53 var SECTION = "15.9.5.25-1";
54 var VERSION = "ECMA_1";
55 startTest();
56
57 writeHeaderToLog( SECTION + " Date.prototype.setUTCMilliseconds(ms)");
58
59 addNewTestCase( 0, 0, "TDATE = new Date(0);(TDATE).setUTCMilliseconds(0);TDATE",
60                 UTCDateFromTime(SetUTCMilliseconds(0,0)),
61                 LocalDateFromTime(SetUTCMilliseconds(0,0)) );
62 addNewTestCase( 28800000,999,
63                 "TDATE = new Date(28800000);(TDATE).setUTCMilliseconds(999);TDATE",
64                 UTCDateFromTime(SetUTCMilliseconds(28800000,999)),
65                 LocalDateFromTime(SetUTCMilliseconds(28800000,999)) );
66 addNewTestCase( 28800000,-28800000,
67                 "TDATE = new Date(28800000);(TDATE).setUTCMilliseconds(-28800000);TDATE",
68                 UTCDateFromTime(SetUTCMilliseconds(28800000,-28800000)),
69                 LocalDateFromTime(SetUTCMilliseconds(28800000,-28800000)) );
70 addNewTestCase( 946684800000,1234567,
71                 "TDATE = new Date(946684800000);(TDATE).setUTCMilliseconds(1234567);TDATE",
72                 UTCDateFromTime(SetUTCMilliseconds(946684800000,1234567)),
73                 LocalDateFromTime(SetUTCMilliseconds(946684800000,1234567)) );
74 addNewTestCase( 946684800000, 123456789,
75                 "TDATE = new Date(946684800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
76                 UTCDateFromTime(SetUTCMilliseconds(946684800000,123456789)),
77                 LocalDateFromTime(SetUTCMilliseconds(946684800000,123456789)) );
78
79 addNewTestCase( -2208988800000,123456789,
80                 "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
81                 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)),
82                 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)) );
83
84 addNewTestCase( -2208988800000,123456,
85                 "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456);TDATE",
86                 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456)),
87                 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456)) );
88
89 addNewTestCase( -2208988800000,-123456,
90                 "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(-123456);TDATE",
91                 UTCDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)),
92                 LocalDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)) );
93
94 addNewTestCase( 0,-999,
95                 "TDATE = new Date(0);(TDATE).setUTCMilliseconds(-999);TDATE",
96                 UTCDateFromTime(SetUTCMilliseconds(0,-999)),
97                 LocalDateFromTime(SetUTCMilliseconds(0,-999)) );
98
99 test();
100
101 function addNewTestCase( initialTime, ms, DateString, UTCDate, LocalDate) {
102   DateCase = new Date(initialTime);
103   DateCase.setUTCMilliseconds(ms);
104
105   new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
106   new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
107
108   new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
109   new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
110   new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
111
112   new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
113   new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
114   new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
115   new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
116
117   new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
118   new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
119   new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
120
121   new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
122   new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
123   new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
124   new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
125
126   DateCase.toString = Object.prototype.toString;
127
128   new TestCase( SECTION,
129                 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
130                 "[object Date]",
131                 DateCase.toString() );
132 }
133 function MyDate() {
134   this.year = 0;
135   this.month = 0;
136   this.date = 0;
137   this.hours = 0;
138   this.minutes = 0;
139   this.seconds = 0;
140   this.ms = 0;
141 }
142 function LocalDateFromTime(t) {
143   t = LocalTime(t);
144   return ( MyDateFromTime(t) );
145 }
146 function UTCDateFromTime(t) {
147   return ( MyDateFromTime(t) );
148 }
149 function MyDateFromTime( t ) {
150   var d = new MyDate();
151   d.year = YearFromTime(t);
152   d.month = MonthFromTime(t);
153   d.date = DateFromTime(t);
154   d.hours = HourFromTime(t);
155   d.minutes = MinFromTime(t);
156   d.seconds = SecFromTime(t);
157   d.ms = msFromTime(t);
158
159   d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
160   d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
161   d.day = WeekDay( d.value );
162
163   return (d);
164 }
165
166 function SetUTCMilliseconds( T, MS ) {
167   T = Number( T );
168   TIME = MakeTime(    HourFromTime(T),
169                       MinFromTime(T),
170                       SecFromTime(T),
171                       MS );
172   return( MakeDate( Day(T), TIME ));
173 }