Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Date / 15.9.3.2-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 /**
41    File Name:          15.9.3.1.js
42    ECMA Section:       15.9.3.1 new Date (year, month, date, hours, minutes, seconds, ms)
43    Description:        The [[Prototype]] property of the newly constructed
44    object is set to the original Date prototype object,
45    the one that is the initial value of Date.prototype.
46
47    The [[Class]] property of the newly constructed object
48    is set as follows:
49    1. Call ToNumber(year)
50    2. Call ToNumber(month)
51    3. Call ToNumber(date)
52    4. Call ToNumber(hours)
53    5. Call ToNumber(minutes)
54    6. Call ToNumber(seconds)
55    7. Call ToNumber(ms)
56    8.  If Result(1)is NaN and 0 <= ToInteger(Result(1)) <=
57    99, Result(8) is 1900+ToInteger(Result(1)); otherwise,
58    Result(8) is Result(1)
59    9.  Compute MakeDay(Result(8), Result(2), Result(3)
60    10. Compute MakeTime(Result(4), Result(5), Result(6),
61    Result(7)
62    11. Compute MakeDate(Result(9), Result(10))
63    12. Set the [[Value]] property of the newly constructed
64    object to TimeClip(UTC(Result(11))).
65
66
67    This tests the returned value of a newly constructed
68    Date object.
69
70    Author:             christine@netscape.com
71    Date:               7 july 1997
72 */
73
74 var TIME        = 0;
75 var UTC_YEAR    = 1;
76 var UTC_MONTH   = 2;
77 var UTC_DATE    = 3;
78 var UTC_DAY     = 4;
79 var UTC_HOURS   = 5;
80 var UTC_MINUTES = 6;
81 var UTC_SECONDS = 7;
82 var UTC_MS      = 8;
83
84 var YEAR        = 9;
85 var MONTH       = 10;
86 var DATE        = 11;
87 var DAY         = 12;
88 var HOURS       = 13;
89 var MINUTES     = 14;
90 var SECONDS     = 15;
91 var MS          = 16;
92
93 //  for TCMS, the gTestcases array must be global.
94 var SECTION = "15.9.3.1";
95 var TITLE =   "Date( year, month, date, hours, minutes, seconds )";
96
97 writeHeaderToLog( SECTION+" " +TITLE );
98
99 // Dates around 1900
100
101 addNewTestCase( new Date(1899,11,31,16,0,0),
102                 "new Date(1899,11,31,16,0,0)",
103                 [-2208988800000,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
104
105 addNewTestCase( new Date(1899,11,31,15,59,59),
106                 "new Date(1899,11,31,15,59,59)",
107                 [-2208988801000,1899,11,31,0,23,59,59,0,1899,11,31,0,15,59,59,0] );
108
109 addNewTestCase( new Date(1900,0,1,0,0,0),
110                 "new Date(1900,0,1,0,0,0)",
111                 [-2208960000000,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
112
113 addNewTestCase( new Date(1900,0,1,0,0,1),
114                 "new Date(1900,0,1,0,0,1)",
115                 [-2208959999000,1900,0,1,1,8,0,1,0,1900,0,1,1,0,0,1,0] );
116
117 test();
118
119 function addNewTestCase( DateCase, DateString, ResultArray ) {
120   //adjust hard-coded ResultArray for tester's timezone instead of PST
121   adjustResultArray(ResultArray);
122
123   new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME],       DateCase.getTime() );
124   new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME],       DateCase.valueOf() );
125
126   new TestCase( SECTION, DateString+".getUTCFullYear()",      ResultArray[UTC_YEAR],   DateCase.getUTCFullYear() );
127   new TestCase( SECTION, DateString+".getUTCMonth()",         ResultArray[UTC_MONTH],  DateCase.getUTCMonth() );
128   new TestCase( SECTION, DateString+".getUTCDate()",          ResultArray[UTC_DATE],   DateCase.getUTCDate() );
129   new TestCase( SECTION, DateString+".getUTCDay()",           ResultArray[UTC_DAY],    DateCase.getUTCDay() );
130   new TestCase( SECTION, DateString+".getUTCHours()",         ResultArray[UTC_HOURS],  DateCase.getUTCHours() );
131   new TestCase( SECTION, DateString+".getUTCMinutes()",       ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
132   new TestCase( SECTION, DateString+".getUTCSeconds()",       ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
133   new TestCase( SECTION, DateString+".getUTCMilliseconds()",  ResultArray[UTC_MS],     DateCase.getUTCMilliseconds() );
134
135   new TestCase( SECTION, DateString+".getFullYear()",         ResultArray[YEAR],       DateCase.getFullYear() );
136   new TestCase( SECTION, DateString+".getMonth()",            ResultArray[MONTH],      DateCase.getMonth() );
137   new TestCase( SECTION, DateString+".getDate()",             ResultArray[DATE],       DateCase.getDate() );
138   new TestCase( SECTION, DateString+".getDay()",              ResultArray[DAY],        DateCase.getDay() );
139   new TestCase( SECTION, DateString+".getHours()",            ResultArray[HOURS],      DateCase.getHours() );
140   new TestCase( SECTION, DateString+".getMinutes()",          ResultArray[MINUTES],    DateCase.getMinutes() );
141   new TestCase( SECTION, DateString+".getSeconds()",          ResultArray[SECONDS],    DateCase.getSeconds() );
142   new TestCase( SECTION, DateString+".getMilliseconds()",     ResultArray[MS],         DateCase.getMilliseconds() );
143
144 }