1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Date/15.9.3.8-3.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,126 @@ 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 2000 1.79 + 1.80 +addNewTestCase( new Date(TIME_2000+TZ_ADJUST), 1.81 + "new Date(" +(TIME_2000+TZ_ADJUST)+")", 1.82 + [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] ); 1.83 + 1.84 +addNewTestCase( new Date(TIME_2000), 1.85 + "new Date(" +TIME_2000+")", 1.86 + [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] ); 1.87 + 1.88 +addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toString()), 1.89 + "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toString()+"\")", 1.90 + [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] ); 1.91 + 1.92 +addNewTestCase( new Date((new Date(TIME_2000)).toString()), 1.93 + "new Date(\"" +(new Date(TIME_2000)).toString()+"\")", 1.94 + [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] ); 1.95 + 1.96 + 1.97 +addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toUTCString()), 1.98 + "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toUTCString()+"\")", 1.99 + [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] ); 1.100 + 1.101 +addNewTestCase( new Date( (new Date(TIME_2000)).toUTCString()), 1.102 + "new Date(\"" +(new Date(TIME_2000)).toUTCString()+"\")", 1.103 + [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] ); 1.104 + 1.105 +test(); 1.106 + 1.107 +function addNewTestCase( DateCase, DateString, ResultArray ) { 1.108 + //adjust hard-coded ResultArray for tester's timezone instead of PST 1.109 + adjustResultArray(ResultArray, 'msMode'); 1.110 + 1.111 + new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME], DateCase.getTime() ); 1.112 + new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME], DateCase.valueOf() ); 1.113 + new TestCase( SECTION, DateString+".getUTCFullYear()", ResultArray[UTC_YEAR], DateCase.getUTCFullYear() ); 1.114 + new TestCase( SECTION, DateString+".getUTCMonth()", ResultArray[UTC_MONTH], DateCase.getUTCMonth() ); 1.115 + new TestCase( SECTION, DateString+".getUTCDate()", ResultArray[UTC_DATE], DateCase.getUTCDate() ); 1.116 + new TestCase( SECTION, DateString+".getUTCDay()", ResultArray[UTC_DAY], DateCase.getUTCDay() ); 1.117 + new TestCase( SECTION, DateString+".getUTCHours()", ResultArray[UTC_HOURS], DateCase.getUTCHours() ); 1.118 + new TestCase( SECTION, DateString+".getUTCMinutes()", ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() ); 1.119 + new TestCase( SECTION, DateString+".getUTCSeconds()", ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() ); 1.120 + new TestCase( SECTION, DateString+".getUTCMilliseconds()", ResultArray[UTC_MS], DateCase.getUTCMilliseconds() ); 1.121 + new TestCase( SECTION, DateString+".getFullYear()", ResultArray[YEAR], DateCase.getFullYear() ); 1.122 + new TestCase( SECTION, DateString+".getMonth()", ResultArray[MONTH], DateCase.getMonth() ); 1.123 + new TestCase( SECTION, DateString+".getDate()", ResultArray[DATE], DateCase.getDate() ); 1.124 + new TestCase( SECTION, DateString+".getDay()", ResultArray[DAY], DateCase.getDay() ); 1.125 + new TestCase( SECTION, DateString+".getHours()", ResultArray[HOURS], DateCase.getHours() ); 1.126 + new TestCase( SECTION, DateString+".getMinutes()", ResultArray[MINUTES], DateCase.getMinutes() ); 1.127 + new TestCase( SECTION, DateString+".getSeconds()", ResultArray[SECONDS], DateCase.getSeconds() ); 1.128 + new TestCase( SECTION, DateString+".getMilliseconds()", ResultArray[MS], DateCase.getMilliseconds() ); 1.129 +}