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