js/src/tests/ecma/Date/15.9.3.1-1.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Date/15.9.3.1-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,205 @@
     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.1.js
    1.12 +   ECMA Section:       15.9.3.1 new Date (year, month, date, hours, minutes, seconds, ms)
    1.13 +   Description:        The [[Prototype]] property of the newly constructed
    1.14 +   object is set to the original Date prototype object,
    1.15 +   the one that is the initial value of Date.prototype.
    1.16 +
    1.17 +   The [[Class]] property of the newly constructed object
    1.18 +   is set as follows:
    1.19 +   1. Call ToNumber(year)
    1.20 +   2. Call ToNumber(month)
    1.21 +   3. Call ToNumber(date)
    1.22 +   4. Call ToNumber(hours)
    1.23 +   5. Call ToNumber(minutes)
    1.24 +   6. Call ToNumber(seconds)
    1.25 +   7. Call ToNumber(ms)
    1.26 +   8.  If Result(1) is NaN and 0 <= ToInteger(Result(1)) <=
    1.27 +   99, Result(8) is 1900+ToInteger(Result(1)); otherwise,
    1.28 +   Result(8) is Result(1)
    1.29 +   9.  Compute MakeDay(Result(8), Result(2), Result(3)
    1.30 +   10. Compute MakeTime(Result(4), Result(5), Result(6),
    1.31 +   Result(7)
    1.32 +   11. Compute MakeDate(Result(9), Result(10))
    1.33 +   12. Set the [[Value]] property of the newly constructed
    1.34 +   object to TimeClip(UTC(Result(11))).
    1.35 +
    1.36 +
    1.37 +   This tests the returned value of a newly constructed
    1.38 +   Date object.
    1.39 +
    1.40 +   Author:             christine@netscape.com
    1.41 +   Date:               7 july 1997
    1.42 +*/
    1.43 +
    1.44 +var SECTION = "15.9.3.1";
    1.45 +var VERSION = "ECMA_1";
    1.46 +startTest();
    1.47 +var TITLE   = "new Date( year, month, date, hours, minutes, seconds, ms )";
    1.48 +
    1.49 +var TIME        = 0;
    1.50 +var UTC_YEAR    = 1;
    1.51 +var UTC_MONTH   = 2;
    1.52 +var UTC_DATE    = 3;
    1.53 +var UTC_DAY     = 4;
    1.54 +var UTC_HOURS   = 5;
    1.55 +var UTC_MINUTES = 6;
    1.56 +var UTC_SECONDS = 7;
    1.57 +var UTC_MS      = 8;
    1.58 +
    1.59 +var YEAR        = 9;
    1.60 +var MONTH       = 10;
    1.61 +var DATE        = 11;
    1.62 +var DAY         = 12;
    1.63 +var HOURS       = 13;
    1.64 +var MINUTES     = 14;
    1.65 +var SECONDS     = 15;
    1.66 +var MS          = 16;
    1.67 +
    1.68 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.69 +
    1.70 +// Dates around 1970
    1.71 +
    1.72 +addNewTestCase( new Date( 1969,11,31,15,59,59,999),
    1.73 +		"new Date( 1969,11,31,15,59,59,999)",
    1.74 +		[TIME_1970-1,1969,11,31,3,23,59,59,999,1969,11,31,3,15,59,59,999] );
    1.75 +
    1.76 +addNewTestCase( new Date( 1969,11,31,23,59,59,999),
    1.77 +		"new Date( 1969,11,31,23,59,59,999)",
    1.78 +		[TIME_1970-PST_ADJUST-1,1970,0,1,4,7,59,59,999,1969,11,31,3,23,59,59,999] );
    1.79 +
    1.80 +addNewTestCase( new Date( 1970,0,1,0,0,0,0),
    1.81 +		"new Date( 1970,0,1,0,0,0,0)",
    1.82 +		[TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
    1.83 +
    1.84 +addNewTestCase( new Date( 1969,11,31,16,0,0,0),
    1.85 +		"new Date( 1969,11,31,16,0,0,0)",
    1.86 +		[TIME_1970,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
    1.87 +
    1.88 +addNewTestCase( new Date(1969,12,1,0,0,0,0),
    1.89 +		"new Date(1969,12,1,0,0,0,0)",
    1.90 +		[TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
    1.91 +
    1.92 +addNewTestCase( new Date(1969,11,32,0,0,0,0),
    1.93 +		"new Date(1969,11,32,0,0,0,0)",
    1.94 +		[TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
    1.95 +
    1.96 +addNewTestCase( new Date(1969,11,31,24,0,0,0),
    1.97 +		"new Date(1969,11,31,24,0,0,0)",
    1.98 +		[TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
    1.99 +
   1.100 +addNewTestCase( new Date(1969,11,31,23,60,0,0),
   1.101 +		"new Date(1969,11,31,23,60,0,0)",
   1.102 +		[TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
   1.103 +
   1.104 +addNewTestCase( new Date(1969,11,31,23,59,60,0),
   1.105 +		"new Date(1969,11,31,23,59,60,0)",
   1.106 +		[TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
   1.107 +
   1.108 +addNewTestCase( new Date(1969,11,31,23,59,59,1000),
   1.109 +		"new Date(1969,11,31,23,59,59,1000)",
   1.110 +		[TIME_1970-PST_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
   1.111 +
   1.112 +// Dates around 2000
   1.113 +
   1.114 +addNewTestCase( new Date( 1999,11,31,15,59,59,999),
   1.115 +		"new Date( 1999,11,31,15,59,59,999)",
   1.116 +		[TIME_2000-1,1999,11,31,5,23,59,59,999,1999,11,31,5,15,59,59,999] );
   1.117 +
   1.118 +addNewTestCase( new Date( 1999,11,31,16,0,0,0),
   1.119 +		"new Date( 1999,11,31,16,0,0,0)",
   1.120 +		[TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5, 16,0,0,0] );
   1.121 +
   1.122 +addNewTestCase( new Date( 1999,11,31,23,59,59,999),
   1.123 +		"new Date( 1999,11,31,23,59,59,999)",
   1.124 +		[TIME_2000-PST_ADJUST-1,2000,0,1,6,7,59,59,999,1999,11,31,5,23,59,59,999] );
   1.125 +
   1.126 +addNewTestCase( new Date( 2000,0,1,0,0,0,0),
   1.127 +		"new Date( 2000,0,1,0,0,0,0)",
   1.128 +		[TIME_2000-PST_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
   1.129 +
   1.130 +addNewTestCase( new Date( 2000,0,1,0,0,0,1),
   1.131 +		"new Date( 2000,0,1,0,0,0,1)",
   1.132 +		[TIME_2000-PST_ADJUST+1,2000,0,1,6,8,0,0,1,2000,0,1,6,0,0,0,1] );
   1.133 +
   1.134 +// Dates around 29 Feb 2000
   1.135 +
   1.136 +addNewTestCase( new Date(2000,1,28,16,0,0,0),
   1.137 +		"new Date(2000,1,28,16,0,0,0)",
   1.138 +		[UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0] );
   1.139 +
   1.140 +addNewTestCase( new Date(2000,1,29,0,0,0,0),
   1.141 +		"new Date(2000,1,29,0,0,0,0)",
   1.142 +		[UTC_FEB_29_2000-PST_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
   1.143 +
   1.144 +addNewTestCase( new Date(2000,1,28,24,0,0,0),
   1.145 +		"new Date(2000,1,28,24,0,0,0)",
   1.146 +		[UTC_FEB_29_2000-PST_ADJUST,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
   1.147 +
   1.148 +// Dates around 1900
   1.149 +
   1.150 +addNewTestCase( new Date(1899,11,31,16,0,0,0),
   1.151 +		"new Date(1899,11,31,16,0,0,0)",
   1.152 +		[TIME_1900,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
   1.153 +
   1.154 +addNewTestCase( new Date(1899,11,31,15,59,59,999),
   1.155 +		"new Date(1899,11,31,15,59,59,999)",
   1.156 +		[TIME_1900-1,1899,11,31,0,23,59,59,999,1899,11,31,0,15,59,59,999] );
   1.157 +
   1.158 +addNewTestCase( new Date(1899,11,31,23,59,59,999),
   1.159 +		"new Date(1899,11,31,23,59,59,999)",
   1.160 +		[TIME_1900-PST_ADJUST-1,1900,0,1,1,7,59,59,999,1899,11,31,0,23,59,59,999] );
   1.161 +
   1.162 +addNewTestCase( new Date(1900,0,1,0,0,0,0),
   1.163 +		"new Date(1900,0,1,0,0,0,0)",
   1.164 +		[TIME_1900-PST_ADJUST,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
   1.165 +
   1.166 +addNewTestCase( new Date(1900,0,1,0,0,0,1),
   1.167 +		"new Date(1900,0,1,0,0,0,1)",
   1.168 +		[TIME_1900-PST_ADJUST+1,1900,0,1,1,8,0,0,1,1900,0,1,1,0,0,0,1] );
   1.169 +
   1.170 +// Dates around 2005
   1.171 +
   1.172 +addNewTestCase( new Date(2005,0,1,0,0,0,0),
   1.173 +		"new Date(2005,0,1,0,0,0,0)",
   1.174 +		[UTC_JAN_1_2005-PST_ADJUST,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] );
   1.175 +
   1.176 +addNewTestCase( new Date(2004,11,31,16,0,0,0),
   1.177 +		"new Date(2004,11,31,16,0,0,0)",
   1.178 +		[UTC_JAN_1_2005,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] );
   1.179 +
   1.180 +test();
   1.181 +
   1.182 +
   1.183 +function addNewTestCase( DateCase, DateString, ResultArray ) {
   1.184 +  //adjust hard-coded ResultArray for tester's timezone instead of PST
   1.185 +  adjustResultArray(ResultArray);
   1.186 +
   1.187 +  new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME],       DateCase.getTime() );
   1.188 +  new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME],       DateCase.valueOf() );
   1.189 +
   1.190 +  new TestCase( SECTION, DateString+".getUTCFullYear()",      ResultArray[UTC_YEAR],  DateCase.getUTCFullYear() );
   1.191 +  new TestCase( SECTION, DateString+".getUTCMonth()",         ResultArray[UTC_MONTH],  DateCase.getUTCMonth() );
   1.192 +  new TestCase( SECTION, DateString+".getUTCDate()",          ResultArray[UTC_DATE],   DateCase.getUTCDate() );
   1.193 +  new TestCase( SECTION, DateString+".getUTCDay()",           ResultArray[UTC_DAY],    DateCase.getUTCDay() );
   1.194 +  new TestCase( SECTION, DateString+".getUTCHours()",         ResultArray[UTC_HOURS],  DateCase.getUTCHours() );
   1.195 +  new TestCase( SECTION, DateString+".getUTCMinutes()",       ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
   1.196 +  new TestCase( SECTION, DateString+".getUTCSeconds()",       ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
   1.197 +  new TestCase( SECTION, DateString+".getUTCMilliseconds()",  ResultArray[UTC_MS],     DateCase.getUTCMilliseconds() );
   1.198 +
   1.199 +  new TestCase( SECTION, DateString+".getFullYear()",         ResultArray[YEAR],       DateCase.getFullYear() );
   1.200 +  new TestCase( SECTION, DateString+".getMonth()",            ResultArray[MONTH],      DateCase.getMonth() );
   1.201 +  new TestCase( SECTION, DateString+".getDate()",             ResultArray[DATE],       DateCase.getDate() );
   1.202 +  new TestCase( SECTION, DateString+".getDay()",              ResultArray[DAY],        DateCase.getDay() );
   1.203 +  new TestCase( SECTION, DateString+".getHours()",            ResultArray[HOURS],      DateCase.getHours() );
   1.204 +  new TestCase( SECTION, DateString+".getMinutes()",          ResultArray[MINUTES],    DateCase.getMinutes() );
   1.205 +  new TestCase( SECTION, DateString+".getSeconds()",          ResultArray[SECONDS],    DateCase.getSeconds() );
   1.206 +  new TestCase( SECTION, DateString+".getMilliseconds()",     ResultArray[MS],         DateCase.getMilliseconds() );
   1.207 +}
   1.208 +

mercurial