Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / ecma / Date / 15.9.3.8-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.3.8.js
42    ECMA Section:       15.9.3.8 The Date Constructor
43    new Date( value )
44    Description:        The [[Prototype]] property of the newly constructed
45    object is set to the original Date prototype object,
46    the one that is the initial valiue of Date.prototype.
47
48    The [[Class]] property of the newly constructed object is
49    set to "Date".
50
51    The [[Value]] property of the newly constructed object is
52    set as follows:
53
54    1. Call ToPrimitive(value)
55    2. If Type( Result(1) ) is String, then go to step 5.
56    3. Let V be  ToNumber( Result(1) ).
57    4. Set the [[Value]] property of the newly constructed
58    object to TimeClip(V) and return.
59    5. Parse Result(1) as a date, in exactly the same manner
60    as for the parse method.  Let V be the time value for
61    this date.
62    6. Go to step 4.
63
64    Author:             christine@netscape.com
65    Date:               28 october 1997
66    Version:            9706
67
68 */
69
70 var VERSION = "ECMA_1";
71 startTest();
72 var SECTION = "15.9.3.8";
73 var TYPEOF  = "object";
74
75 var TIME        = 0;
76 var UTC_YEAR    = 1;
77 var UTC_MONTH   = 2;
78 var UTC_DATE    = 3;
79 var UTC_DAY     = 4;
80 var UTC_HOURS   = 5;
81 var UTC_MINUTES = 6;
82 var UTC_SECONDS = 7;
83 var UTC_MS      = 8;
84
85 var YEAR        = 9;
86 var MONTH       = 10;
87 var DATE        = 11;
88 var DAY         = 12;
89 var HOURS       = 13;
90 var MINUTES     = 14;
91 var SECONDS     = 15;
92 var MS          = 16;
93
94
95 //  for TCMS, the gTestcases array must be global.
96 var gTc= 0;
97 var TITLE = "Date constructor:  new Date( value )";
98 var SECTION = "15.9.3.8";
99 var VERSION = "ECMA_1";
100 startTest();
101
102 writeHeaderToLog( SECTION +" " + TITLE );
103
104 // all the "ResultArrays" below are hard-coded to Pacific Standard Time values -
105 var TZ_ADJUST = -TZ_PST * msPerHour;
106
107
108 // Dates around 1970
109 addNewTestCase( new Date(0),
110                 "new Date(0)",
111                 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
112
113 addNewTestCase( new Date(1),
114                 "new Date(1)",
115                 [1,1970,0,1,4,0,0,0,1,1969,11,31,3,16,0,0,1] );
116
117 addNewTestCase( new Date(true),
118                 "new Date(true)",
119                 [1,1970,0,1,4,0,0,0,1,1969,11,31,3,16,0,0,1] );
120
121 addNewTestCase( new Date(false),
122                 "new Date(false)",
123                 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
124
125 addNewTestCase( new Date( (new Date(0)).toString() ),
126                 "new Date(\""+ (new Date(0)).toString()+"\" )",
127                 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
128
129 test();
130
131 function addNewTestCase( DateCase, DateString, ResultArray ) {
132   //adjust hard-coded ResultArray for tester's timezone instead of PST
133   adjustResultArray(ResultArray, 'msMode');
134
135
136   new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME],       DateCase.getTime() );
137   new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME],       DateCase.valueOf() );
138   new TestCase( SECTION, DateString+".getUTCFullYear()",      ResultArray[UTC_YEAR], DateCase.getUTCFullYear() );
139   new TestCase( SECTION, DateString+".getUTCMonth()",         ResultArray[UTC_MONTH],  DateCase.getUTCMonth() );
140   new TestCase( SECTION, DateString+".getUTCDate()",          ResultArray[UTC_DATE],   DateCase.getUTCDate() );
141   new TestCase( SECTION, DateString+".getUTCDay()",           ResultArray[UTC_DAY],    DateCase.getUTCDay() );
142   new TestCase( SECTION, DateString+".getUTCHours()",         ResultArray[UTC_HOURS],  DateCase.getUTCHours() );
143   new TestCase( SECTION, DateString+".getUTCMinutes()",       ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
144   new TestCase( SECTION, DateString+".getUTCSeconds()",       ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
145   new TestCase( SECTION, DateString+".getUTCMilliseconds()",  ResultArray[UTC_MS],     DateCase.getUTCMilliseconds() );
146   new TestCase( SECTION, DateString+".getFullYear()",         ResultArray[YEAR],       DateCase.getFullYear() );
147   new TestCase( SECTION, DateString+".getMonth()",            ResultArray[MONTH],      DateCase.getMonth() );
148   new TestCase( SECTION, DateString+".getDate()",             ResultArray[DATE],       DateCase.getDate() );
149   new TestCase( SECTION, DateString+".getDay()",              ResultArray[DAY],        DateCase.getDay() );
150   new TestCase( SECTION, DateString+".getHours()",            ResultArray[HOURS],      DateCase.getHours() );
151   new TestCase( SECTION, DateString+".getMinutes()",          ResultArray[MINUTES],    DateCase.getMinutes() );
152   new TestCase( SECTION, DateString+".getSeconds()",          ResultArray[SECONDS],    DateCase.getSeconds() );
153   new TestCase( SECTION, DateString+".getMilliseconds()",     ResultArray[MS],         DateCase.getMilliseconds() );
154 }