Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Date / 15.9.4.3.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 var SECTION = "15.9.4.3";
41 var TITLE = "Date.UTC( year, month, date, hours, minutes, seconds, ms )";
42
43 // Dates around 1970
44
45 addNewTestCase( Date.UTC( 1970,0,1,0,0,0,0),
46                 "Date.UTC( 1970,0,1,0,0,0,0)",
47                 utc(1970,0,1,0,0,0,0) );
48
49 addNewTestCase( Date.UTC( 1969,11,31,23,59,59,999),
50                 "Date.UTC( 1969,11,31,23,59,59,999)",
51                 utc(1969,11,31,23,59,59,999) );
52 addNewTestCase( Date.UTC( 1972,1,29,23,59,59,999),
53                 "Date.UTC( 1972,1,29,23,59,59,999)",
54                 utc(1972,1,29,23,59,59,999) );
55 addNewTestCase( Date.UTC( 1972,2,1,23,59,59,999),
56                 "Date.UTC( 1972,2,1,23,59,59,999)",
57                 utc(1972,2,1,23,59,59,999) );
58 addNewTestCase( Date.UTC( 1968,1,29,23,59,59,999),
59                 "Date.UTC( 1968,1,29,23,59,59,999)",
60                 utc(1968,1,29,23,59,59,999) );
61 addNewTestCase( Date.UTC( 1968,2,1,23,59,59,999),
62                 "Date.UTC( 1968,2,1,23,59,59,999)",
63                 utc(1968,2,1,23,59,59,999) );
64 addNewTestCase( Date.UTC( 1969,0,1,0,0,0,0),
65                 "Date.UTC( 1969,0,1,0,0,0,0)",
66                 utc(1969,0,1,0,0,0,0) );
67 addNewTestCase( Date.UTC( 1969,11,31,23,59,59,1000),
68                 "Date.UTC( 1969,11,31,23,59,59,1000)",
69                 utc(1970,0,1,0,0,0,0) );
70 addNewTestCase( Date.UTC( 1969,Number.NaN,31,23,59,59,999),
71                 "Date.UTC( 1969,Number.NaN,31,23,59,59,999)",
72                 utc(1969,Number.NaN,31,23,59,59,999) );
73
74 // Dates around 2000
75
76 addNewTestCase( Date.UTC( 1999,11,31,23,59,59,999),
77                 "Date.UTC( 1999,11,31,23,59,59,999)",
78                 utc(1999,11,31,23,59,59,999) );
79 addNewTestCase( Date.UTC( 2000,0,1,0,0,0,0),
80                 "Date.UTC( 2000,0,1,0,0,0,0)",
81                 utc(2000,0,1,0,0,0,0) );
82
83 // Dates around 1900
84 addNewTestCase( Date.UTC( 1899,11,31,23,59,59,999),
85                 "Date.UTC( 1899,11,31,23,59,59,999)",
86                 utc(1899,11,31,23,59,59,999) );
87 addNewTestCase( Date.UTC( 1900,0,1,0,0,0,0),
88                 "Date.UTC( 1900,0,1,0,0,0,0)",
89                 utc(1900,0,1,0,0,0,0) );
90 addNewTestCase( Date.UTC( 1973,0,1,0,0,0,0),
91                 "Date.UTC( 1973,0,1,0,0,0,0)",
92                 utc(1973,0,1,0,0,0,0) );
93 addNewTestCase( Date.UTC( 1776,6,4,12,36,13,111),
94                 "Date.UTC( 1776,6,4,12,36,13,111)",
95                 utc(1776,6,4,12,36,13,111) );
96 addNewTestCase( Date.UTC( 2525,9,18,15,30,1,123),
97                 "Date.UTC( 2525,9,18,15,30,1,123)",
98                 utc(2525,9,18,15,30,1,123) );
99
100 // Dates around 29 Feb 2000
101
102 addNewTestCase( Date.UTC( 2000,1,29,0,0,0,0 ),
103                 "Date.UTC( 2000,1,29,0,0,0,0 )",
104                 utc(2000,1,29,0,0,0,0) );
105 addNewTestCase( Date.UTC( 2000,1,29,8,0,0,0 ),
106                 "Date.UTC( 2000,1,29,8,0,0,0 )",
107                 utc(2000,1,29,8,0,0,0) );
108
109 // Dates around 1 Jan 2005
110
111 addNewTestCase( Date.UTC( 2005,0,1,0,0,0,0 ),
112                 "Date.UTC( 2005,0,1,0,0,0,0 )",
113                 utc(2005,0,1,0,0,0,0) );
114 addNewTestCase( Date.UTC( 2004,11,31,16,0,0,0 ),
115                 "Date.UTC( 2004,11,31,16,0,0,0 )",
116                 utc(2004,11,31,16,0,0,0) );
117
118 test();
119
120 function addNewTestCase( DateCase, DateString, ExpectDate) {
121   DateCase = DateCase;
122
123   new TestCase( SECTION, DateString,         ExpectDate.value,       DateCase );
124   new TestCase( SECTION, DateString,         ExpectDate.value,       DateCase );
125 }
126
127 function MyDate() {
128   this.year = 0;
129   this.month = 0;
130   this.date = 0;
131   this.hours = 0;
132   this.minutes = 0;
133   this.seconds = 0;
134   this.ms = 0;
135 }
136
137 function utc( year, month, date, hours, minutes, seconds, ms ) {
138   d = new MyDate();
139   d.year      = Number(year);
140
141   if (month)
142     d.month     = Number(month);
143   if (date)
144     d.date      = Number(date);
145   if (hours)
146     d.hours     = Number(hours);
147   if (minutes)
148     d.minutes   = Number(minutes);
149   if (seconds)
150     d.seconds   = Number(seconds);
151   if (ms)
152     d.ms        = Number(ms);
153
154   if ( isNaN(d.year) && 0 <= ToInteger(d.year) && d.year <= 99 ) {
155     d.year = 1900 + ToInteger(d.year);
156   }
157
158   if (isNaN(month) || isNaN(year) || isNaN(date) || isNaN(hours) ||
159       isNaN(minutes) || isNaN(seconds) || isNaN(ms) ) {
160     d.year = Number.NaN;
161     d.month = Number.NaN;
162     d.date = Number.NaN;
163     d.hours = Number.NaN;
164     d.minutes = Number.NaN;
165     d.seconds = Number.NaN;
166     d.ms = Number.NaN;
167     d.value = Number.NaN;
168     d.time = Number.NaN;
169     d.day =Number.NaN;
170     return d;
171   }
172
173   d.day = MakeDay( d.year, d.month, d.date );
174   d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
175   d.value = (TimeClip( MakeDate(d.day,d.time)));
176
177   return d;
178 }
179
180 function UTCTime( t ) {
181   sign = ( t < 0 ) ? -1 : 1;
182   return ( (t +(TZ_DIFF*msPerHour)) );
183 }
184