1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Date/15.9.3.8-5.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,127 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + File Name: 15.9.3.8.js 1.12 + ECMA Section: 15.9.3.8 The Date Constructor 1.13 + new Date( value ) 1.14 + Description: The [[Prototype]] property of the newly constructed 1.15 + object is set to the original Date prototype object, 1.16 + the one that is the initial valiue of Date.prototype. 1.17 + 1.18 + The [[Class]] property of the newly constructed object is 1.19 + set to "Date". 1.20 + 1.21 + The [[Value]] property of the newly constructed object is 1.22 + set as follows: 1.23 + 1.24 + 1. Call ToPrimitive(value) 1.25 + 2. If Type( Result(1) ) is String, then go to step 5. 1.26 + 3. Let V be ToNumber( Result(1) ). 1.27 + 4. Set the [[Value]] property of the newly constructed 1.28 + object to TimeClip(V) and return. 1.29 + 5. Parse Result(1) as a date, in exactly the same manner 1.30 + as for the parse method. Let V be the time value for 1.31 + this date. 1.32 + 6. Go to step 4. 1.33 + 1.34 + Author: christine@netscape.com 1.35 + Date: 28 october 1997 1.36 + Version: 9706 1.37 + 1.38 +*/ 1.39 + 1.40 +var VERSION = "ECMA_1"; 1.41 +startTest(); 1.42 +var SECTION = "15.9.3.8"; 1.43 +var TYPEOF = "object"; 1.44 + 1.45 +var TIME = 0; 1.46 +var UTC_YEAR = 1; 1.47 +var UTC_MONTH = 2; 1.48 +var UTC_DATE = 3; 1.49 +var UTC_DAY = 4; 1.50 +var UTC_HOURS = 5; 1.51 +var UTC_MINUTES = 6; 1.52 +var UTC_SECONDS = 7; 1.53 +var UTC_MS = 8; 1.54 + 1.55 +var YEAR = 9; 1.56 +var MONTH = 10; 1.57 +var DATE = 11; 1.58 +var DAY = 12; 1.59 +var HOURS = 13; 1.60 +var MINUTES = 14; 1.61 +var SECONDS = 15; 1.62 +var MS = 16; 1.63 + 1.64 + 1.65 +// for TCMS, the gTestcases array must be global. 1.66 +var gTc= 0; 1.67 +var TITLE = "Date constructor: new Date( value )"; 1.68 +var SECTION = "15.9.3.8"; 1.69 +var VERSION = "ECMA_1"; 1.70 +startTest(); 1.71 + 1.72 +writeHeaderToLog( SECTION +" " + TITLE ); 1.73 + 1.74 +// all the "ResultArrays" below are hard-coded to Pacific Standard Time values - 1.75 +var TZ_ADJUST = -TZ_PST * msPerHour; 1.76 + 1.77 + 1.78 +// Dates around 1900 1.79 + 1.80 +var PST_1900 = TIME_1900 + 8*msPerHour; 1.81 + 1.82 +addNewTestCase( new Date( TIME_1900 ), 1.83 + "new Date("+TIME_1900+")", 1.84 + [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] ); 1.85 + 1.86 +addNewTestCase( new Date(PST_1900), 1.87 + "new Date("+PST_1900+")", 1.88 + [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] ); 1.89 + 1.90 +addNewTestCase( new Date( (new Date(TIME_1900)).toString() ), 1.91 + "new Date(\""+(new Date(TIME_1900)).toString()+"\")", 1.92 + [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] ); 1.93 + 1.94 +addNewTestCase( new Date( (new Date(PST_1900)).toString() ), 1.95 + "new Date(\""+(new Date(PST_1900 )).toString()+"\")", 1.96 + [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] ); 1.97 + 1.98 +addNewTestCase( new Date( (new Date(TIME_1900)).toUTCString() ), 1.99 + "new Date(\""+(new Date(TIME_1900)).toUTCString()+"\")", 1.100 + [TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] ); 1.101 + 1.102 +addNewTestCase( new Date( (new Date(PST_1900)).toUTCString() ), 1.103 + "new Date(\""+(new Date(PST_1900 )).toUTCString()+"\")", 1.104 + [ PST_1900,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] ); 1.105 + 1.106 +test(); 1.107 + 1.108 +function addNewTestCase( DateCase, DateString, ResultArray ) { 1.109 + //adjust hard-coded ResultArray for tester's timezone instead of PST 1.110 + adjustResultArray(ResultArray, 'msMode'); 1.111 + 1.112 + new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME], DateCase.getTime() ); 1.113 + new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME], DateCase.valueOf() ); 1.114 + new TestCase( SECTION, DateString+".getUTCFullYear()", ResultArray[UTC_YEAR], DateCase.getUTCFullYear() ); 1.115 + new TestCase( SECTION, DateString+".getUTCMonth()", ResultArray[UTC_MONTH], DateCase.getUTCMonth() ); 1.116 + new TestCase( SECTION, DateString+".getUTCDate()", ResultArray[UTC_DATE], DateCase.getUTCDate() ); 1.117 + new TestCase( SECTION, DateString+".getUTCDay()", ResultArray[UTC_DAY], DateCase.getUTCDay() ); 1.118 + new TestCase( SECTION, DateString+".getUTCHours()", ResultArray[UTC_HOURS], DateCase.getUTCHours() ); 1.119 + new TestCase( SECTION, DateString+".getUTCMinutes()", ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() ); 1.120 + new TestCase( SECTION, DateString+".getUTCSeconds()", ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() ); 1.121 + new TestCase( SECTION, DateString+".getUTCMilliseconds()", ResultArray[UTC_MS], DateCase.getUTCMilliseconds() ); 1.122 + new TestCase( SECTION, DateString+".getFullYear()", ResultArray[YEAR], DateCase.getFullYear() ); 1.123 + new TestCase( SECTION, DateString+".getMonth()", ResultArray[MONTH], DateCase.getMonth() ); 1.124 + new TestCase( SECTION, DateString+".getDate()", ResultArray[DATE], DateCase.getDate() ); 1.125 + new TestCase( SECTION, DateString+".getDay()", ResultArray[DAY], DateCase.getDay() ); 1.126 + new TestCase( SECTION, DateString+".getHours()", ResultArray[HOURS], DateCase.getHours() ); 1.127 + new TestCase( SECTION, DateString+".getMinutes()", ResultArray[MINUTES], DateCase.getMinutes() ); 1.128 + new TestCase( SECTION, DateString+".getSeconds()", ResultArray[SECONDS], DateCase.getSeconds() ); 1.129 + new TestCase( SECTION, DateString+".getMilliseconds()", ResultArray[MS], DateCase.getMilliseconds() ); 1.130 +}