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