michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 15.9.3.8.js michael@0: ECMA Section: 15.9.3.8 The Date Constructor michael@0: new Date( value ) michael@0: Description: The [[Prototype]] property of the newly constructed michael@0: object is set to the original Date prototype object, michael@0: the one that is the initial valiue of Date.prototype. michael@0: michael@0: The [[Class]] property of the newly constructed object is michael@0: set to "Date". michael@0: michael@0: The [[Value]] property of the newly constructed object is michael@0: set as follows: michael@0: michael@0: 1. Call ToPrimitive(value) michael@0: 2. If Type( Result(1) ) is String, then go to step 5. michael@0: 3. Let V be ToNumber( Result(1) ). michael@0: 4. Set the [[Value]] property of the newly constructed michael@0: object to TimeClip(V) and return. michael@0: 5. Parse Result(1) as a date, in exactly the same manner michael@0: as for the parse method. Let V be the time value for michael@0: this date. michael@0: 6. Go to step 4. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 28 october 1997 michael@0: Version: 9706 michael@0: michael@0: */ michael@0: michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var SECTION = "15.9.3.8"; michael@0: var TYPEOF = "object"; michael@0: michael@0: var TIME = 0; michael@0: var UTC_YEAR = 1; michael@0: var UTC_MONTH = 2; michael@0: var UTC_DATE = 3; michael@0: var UTC_DAY = 4; michael@0: var UTC_HOURS = 5; michael@0: var UTC_MINUTES = 6; michael@0: var UTC_SECONDS = 7; michael@0: var UTC_MS = 8; michael@0: michael@0: var YEAR = 9; michael@0: var MONTH = 10; michael@0: var DATE = 11; michael@0: var DAY = 12; michael@0: var HOURS = 13; michael@0: var MINUTES = 14; michael@0: var SECONDS = 15; michael@0: var MS = 16; michael@0: michael@0: michael@0: // for TCMS, the gTestcases array must be global. michael@0: var gTc= 0; michael@0: var TITLE = "Date constructor: new Date( value )"; michael@0: var SECTION = "15.9.3.8"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION +" " + TITLE ); michael@0: michael@0: // all the "ResultArrays" below are hard-coded to Pacific Standard Time values - michael@0: var TZ_ADJUST = -TZ_PST * msPerHour; michael@0: michael@0: michael@0: // Dates around 2000 michael@0: michael@0: addNewTestCase( new Date(TIME_2000+TZ_ADJUST), michael@0: "new Date(" +(TIME_2000+TZ_ADJUST)+")", michael@0: [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] ); michael@0: michael@0: addNewTestCase( new Date(TIME_2000), michael@0: "new Date(" +TIME_2000+")", michael@0: [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] ); michael@0: michael@0: addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toString()), michael@0: "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toString()+"\")", michael@0: [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] ); michael@0: michael@0: addNewTestCase( new Date((new Date(TIME_2000)).toString()), michael@0: "new Date(\"" +(new Date(TIME_2000)).toString()+"\")", michael@0: [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] ); michael@0: michael@0: michael@0: addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toUTCString()), michael@0: "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toUTCString()+"\")", michael@0: [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] ); michael@0: michael@0: addNewTestCase( new Date( (new Date(TIME_2000)).toUTCString()), michael@0: "new Date(\"" +(new Date(TIME_2000)).toUTCString()+"\")", michael@0: [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] ); michael@0: michael@0: test(); michael@0: michael@0: function addNewTestCase( DateCase, DateString, ResultArray ) { michael@0: //adjust hard-coded ResultArray for tester's timezone instead of PST michael@0: adjustResultArray(ResultArray, 'msMode'); michael@0: michael@0: new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME], DateCase.getTime() ); michael@0: new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME], DateCase.valueOf() ); michael@0: new TestCase( SECTION, DateString+".getUTCFullYear()", ResultArray[UTC_YEAR], DateCase.getUTCFullYear() ); michael@0: new TestCase( SECTION, DateString+".getUTCMonth()", ResultArray[UTC_MONTH], DateCase.getUTCMonth() ); michael@0: new TestCase( SECTION, DateString+".getUTCDate()", ResultArray[UTC_DATE], DateCase.getUTCDate() ); michael@0: new TestCase( SECTION, DateString+".getUTCDay()", ResultArray[UTC_DAY], DateCase.getUTCDay() ); michael@0: new TestCase( SECTION, DateString+".getUTCHours()", ResultArray[UTC_HOURS], DateCase.getUTCHours() ); michael@0: new TestCase( SECTION, DateString+".getUTCMinutes()", ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() ); michael@0: new TestCase( SECTION, DateString+".getUTCSeconds()", ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() ); michael@0: new TestCase( SECTION, DateString+".getUTCMilliseconds()", ResultArray[UTC_MS], DateCase.getUTCMilliseconds() ); michael@0: new TestCase( SECTION, DateString+".getFullYear()", ResultArray[YEAR], DateCase.getFullYear() ); michael@0: new TestCase( SECTION, DateString+".getMonth()", ResultArray[MONTH], DateCase.getMonth() ); michael@0: new TestCase( SECTION, DateString+".getDate()", ResultArray[DATE], DateCase.getDate() ); michael@0: new TestCase( SECTION, DateString+".getDay()", ResultArray[DAY], DateCase.getDay() ); michael@0: new TestCase( SECTION, DateString+".getHours()", ResultArray[HOURS], DateCase.getHours() ); michael@0: new TestCase( SECTION, DateString+".getMinutes()", ResultArray[MINUTES], DateCase.getMinutes() ); michael@0: new TestCase( SECTION, DateString+".getSeconds()", ResultArray[SECONDS], DateCase.getSeconds() ); michael@0: new TestCase( SECTION, DateString+".getMilliseconds()", ResultArray[MS], DateCase.getMilliseconds() ); michael@0: }