Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma_3 / 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 JavaScript Engine testing utilities.
16  *
17  * The Initial Developer of the Original Code is
18  * Mozilla Foundation.
19  * Portions created by the Initial Developer are Copyright (C) 2007
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s): nanto_vi (TOYAMA Nao)
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 //-----------------------------------------------------------------------------
39 var BUGNUMBER = 363578;
40 var summary = '15.9.4.3 - Date.UTC edge-case arguments.';
41 var actual = '';
42 var expect = '';
43
44
45 //-----------------------------------------------------------------------------
46 test();
47 //-----------------------------------------------------------------------------
48
49 function test()
50 {
51   enterFunc ('test');
52   printBugNumber(BUGNUMBER);
53   printStatus (summary);
54  
55   //
56
57   expect = 31;
58   actual = (new Date(Date.UTC(2006, 0, 0)).getUTCDate());
59   reportCompare(expect, actual, summary + ': date 0');
60
61   expect = 0;
62   actual = (new Date(Date.UTC(2006, 0, 0, 0)).getUTCHours());
63   reportCompare(expect, actual, summary + ': hours 0');
64
65   expect = 0;
66   actual = (new Date(Date.UTC(2006, 0, 0, 0, 0)).getUTCMinutes());
67   reportCompare(expect, actual, summary + ': minutes 0');
68
69   expect = 0;
70   actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, 0)).getUTCSeconds());
71   reportCompare(expect, actual, summary + ': seconds 0');
72
73   expect = 0;
74   actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, 0, 0)).getUTCMilliseconds());
75   reportCompare(expect, actual, summary + ': milliseconds 0');
76
77   //
78
79   expect = 30;
80   actual = (new Date(Date.UTC(2006, 0, -1)).getUTCDate());
81   reportCompare(expect, actual, summary + ': date -1');
82
83   expect = 23;
84   actual = (new Date(Date.UTC(2006, 0, 0, -1)).getUTCHours());
85   reportCompare(expect, actual, summary + ': hours -1');
86
87   expect = 59;
88   actual = (new Date(Date.UTC(2006, 0, 0, 0, -1)).getUTCMinutes());
89   reportCompare(expect, actual, summary + ': minutes -1');
90
91   expect = 59;
92   actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, -1)).getUTCSeconds());
93   reportCompare(expect, actual, summary + ': seconds -1');
94
95   expect = 999;
96   actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, 0, -1)).getUTCMilliseconds());
97   reportCompare(expect, actual, summary + ': milliseconds -1');
98
99   //
100
101   expect = true;
102   actual = isNaN(new Date(Date.UTC(2006, 0, undefined)).getUTCDate());
103   reportCompare(expect, actual, summary + ': date undefined');
104
105   expect = true;
106   actual = isNaN(new Date(Date.UTC(2006, 0, 0, undefined)).getUTCHours());
107   reportCompare(expect, actual, summary + ': hours undefined');
108
109   expect = true;
110   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, undefined)).getUTCMinutes());
111   reportCompare(expect, actual, summary + ': minutes undefined');
112
113   expect = true;
114   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, undefined)).getUTCSeconds());
115   reportCompare(expect, actual, summary + ': seconds undefined');
116
117   expect = true;
118   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, undefined)).getUTCMilliseconds());
119   reportCompare(expect, actual, summary + ': milliseconds undefined');
120
121   //
122
123   expect = true;
124   actual = isNaN(new Date(Date.UTC(2006, 0, {})).getUTCDate());
125   reportCompare(expect, actual, summary + ': date {}');
126
127   expect = true;
128   actual = isNaN(new Date(Date.UTC(2006, 0, 0, {})).getUTCHours());
129   reportCompare(expect, actual, summary + ': hours {}');
130
131   expect = true;
132   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, {})).getUTCMinutes());
133   reportCompare(expect, actual, summary + ': minutes {}');
134
135   expect = true;
136   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, {})).getUTCSeconds());
137   reportCompare(expect, actual, summary + ': seconds {}');
138
139   expect = true;
140   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, {})).getUTCMilliseconds());
141   reportCompare(expect, actual, summary + ': milliseconds {}');
142
143   //
144
145   expect = 31;
146   actual = (new Date(Date.UTC(2006, 0, null)).getUTCDate());
147   reportCompare(expect, actual, summary + ': date null');
148
149   expect = 0;
150   actual = (new Date(Date.UTC(2006, 0, 0, null)).getUTCHours());
151   reportCompare(expect, actual, summary + ': hours null');
152
153   expect = 0;
154   actual = (new Date(Date.UTC(2006, 0, 0, 0, null)).getUTCMinutes());
155   reportCompare(expect, actual, summary + ': minutes null');
156
157   expect = 0;
158   actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, null)).getUTCSeconds());
159   reportCompare(expect, actual, summary + ': seconds null');
160
161   expect = 0;
162   actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, 0, null)).getUTCMilliseconds());
163   reportCompare(expect, actual, summary + ': milliseconds null');
164
165   //
166
167   expect = true;
168   actual = isNaN(new Date(Date.UTC(2006, 0, Infinity)).getUTCDate());
169   reportCompare(expect, actual, summary + ': date Infinity');
170
171   expect = true;
172   actual = isNaN(new Date(Date.UTC(2006, 0, 0, Infinity)).getUTCHours());
173   reportCompare(expect, actual, summary + ': hours Infinity');
174
175   expect = true;
176   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, Infinity)).getUTCMinutes());
177   reportCompare(expect, actual, summary + ': minutes Infinity');
178
179   expect = true;
180   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, Infinity)).getUTCSeconds());
181   reportCompare(expect, actual, summary + ': seconds Infinity');
182
183   expect = true;
184   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, Infinity)).getUTCMilliseconds());
185   reportCompare(expect, actual, summary + ': milliseconds Infinity');
186
187   //
188
189   expect = true;
190   actual = isNaN(new Date(Date.UTC(2006, 0, -Infinity)).getUTCDate());
191   reportCompare(expect, actual, summary + ': date -Infinity');
192
193   expect = true;
194   actual = isNaN(new Date(Date.UTC(2006, 0, 0, -Infinity)).getUTCHours());
195   reportCompare(expect, actual, summary + ': hours -Infinity');
196
197   expect = true;
198   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, -Infinity)).getUTCMinutes());
199   reportCompare(expect, actual, summary + ': minutes -Infinity');
200
201   expect = true;
202   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, -Infinity)).getUTCSeconds());
203   reportCompare(expect, actual, summary + ': seconds -Infinity');
204
205   expect = true;
206   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, -Infinity)).getUTCMilliseconds());
207   reportCompare(expect, actual, summary + ': milliseconds -Infinity');
208
209   //
210
211   expect = true;
212   actual = isNaN(new Date(Date.UTC(2006, 0, NaN)).getUTCDate());
213   reportCompare(expect, actual, summary + ': date NaN');
214
215   expect = true;
216   actual = isNaN(new Date(Date.UTC(2006, 0, 0, NaN)).getUTCHours());
217   reportCompare(expect, actual, summary + ': hours NaN');
218
219   expect = true;
220   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, NaN)).getUTCMinutes());
221   reportCompare(expect, actual, summary + ': minutes NaN');
222
223   expect = true;
224   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, NaN)).getUTCSeconds());
225   reportCompare(expect, actual, summary + ': seconds NaN');
226
227   expect = true;
228   actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, NaN)).getUTCMilliseconds());
229   reportCompare(expect, actual, summary + ': milliseconds NaN');
230
231   exitFunc ('test');
232 }