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
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/
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
15 * The Original Code is Mozilla Communicator client code, released
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.
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.
37 * ***** END LICENSE BLOCK ***** */
41 File Name: 15.9.3.8.js
42 ECMA Section: 15.9.3.8 The Date Constructor
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.
48 The [[Class]] property of the newly constructed object is
51 The [[Value]] property of the newly constructed object is
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
64 Author: christine@netscape.com
70 var VERSION = "ECMA_1";
72 var SECTION = "15.9.3.8";
73 var TYPEOF = "object";
95 // for TCMS, the gTestcases array must be global.
97 var TITLE = "Date constructor: new Date( value )";
98 var SECTION = "15.9.3.8";
99 var VERSION = "ECMA_1";
102 writeHeaderToLog( SECTION +" " + TITLE );
104 // all the "ResultArrays" below are hard-coded to Pacific Standard Time values -
105 var TZ_ADJUST = -TZ_PST * msPerHour;
107 addNewTestCase( new Date((new Date(0)).toUTCString()),
108 "new Date(\""+ (new Date(0)).toUTCString()+"\" )",
109 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
111 addNewTestCase( new Date((new Date(1)).toString()),
112 "new Date(\""+ (new Date(1)).toString()+"\" )",
113 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
115 addNewTestCase( new Date( TZ_ADJUST ),
116 "new Date(" + TZ_ADJUST+")",
117 [TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
119 addNewTestCase( new Date((new Date(TZ_ADJUST)).toString()),
120 "new Date(\""+ (new Date(TZ_ADJUST)).toString()+"\")",
121 [TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
124 addNewTestCase( new Date( (new Date(TZ_ADJUST)).toUTCString() ),
125 "new Date(\""+ (new Date(TZ_ADJUST)).toUTCString()+"\")",
126 [TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
130 function addNewTestCase( DateCase, DateString, ResultArray ) {
131 //adjust hard-coded ResultArray for tester's timezone instead of PST
132 adjustResultArray(ResultArray, 'msMode');
134 new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME], DateCase.getTime() );
135 new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME], DateCase.valueOf() );
136 new TestCase( SECTION, DateString+".getUTCFullYear()", ResultArray[UTC_YEAR], DateCase.getUTCFullYear() );
137 new TestCase( SECTION, DateString+".getUTCMonth()", ResultArray[UTC_MONTH], DateCase.getUTCMonth() );
138 new TestCase( SECTION, DateString+".getUTCDate()", ResultArray[UTC_DATE], DateCase.getUTCDate() );
139 new TestCase( SECTION, DateString+".getUTCDay()", ResultArray[UTC_DAY], DateCase.getUTCDay() );
140 new TestCase( SECTION, DateString+".getUTCHours()", ResultArray[UTC_HOURS], DateCase.getUTCHours() );
141 new TestCase( SECTION, DateString+".getUTCMinutes()", ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
142 new TestCase( SECTION, DateString+".getUTCSeconds()", ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
143 new TestCase( SECTION, DateString+".getUTCMilliseconds()", ResultArray[UTC_MS], DateCase.getUTCMilliseconds() );
144 new TestCase( SECTION, DateString+".getFullYear()", ResultArray[YEAR], DateCase.getFullYear() );
145 new TestCase( SECTION, DateString+".getMonth()", ResultArray[MONTH], DateCase.getMonth() );
146 new TestCase( SECTION, DateString+".getDate()", ResultArray[DATE], DateCase.getDate() );
147 new TestCase( SECTION, DateString+".getDay()", ResultArray[DAY], DateCase.getDay() );
148 new TestCase( SECTION, DateString+".getHours()", ResultArray[HOURS], DateCase.getHours() );
149 new TestCase( SECTION, DateString+".getMinutes()", ResultArray[MINUTES], DateCase.getMinutes() );
150 new TestCase( SECTION, DateString+".getSeconds()", ResultArray[SECONDS], DateCase.getSeconds() );
151 new TestCase( SECTION, DateString+".getMilliseconds()", ResultArray[MS], DateCase.getMilliseconds() );