js/src/tests/ecma/Date/15.9.3.8-3.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e72ffde1910b
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
7 /**
8 File Name: 15.9.3.8.js
9 ECMA Section: 15.9.3.8 The Date Constructor
10 new Date( value )
11 Description: The [[Prototype]] property of the newly constructed
12 object is set to the original Date prototype object,
13 the one that is the initial valiue of Date.prototype.
14
15 The [[Class]] property of the newly constructed object is
16 set to "Date".
17
18 The [[Value]] property of the newly constructed object is
19 set as follows:
20
21 1. Call ToPrimitive(value)
22 2. If Type( Result(1) ) is String, then go to step 5.
23 3. Let V be ToNumber( Result(1) ).
24 4. Set the [[Value]] property of the newly constructed
25 object to TimeClip(V) and return.
26 5. Parse Result(1) as a date, in exactly the same manner
27 as for the parse method. Let V be the time value for
28 this date.
29 6. Go to step 4.
30
31 Author: christine@netscape.com
32 Date: 28 october 1997
33 Version: 9706
34
35 */
36
37 var VERSION = "ECMA_1";
38 startTest();
39 var SECTION = "15.9.3.8";
40 var TYPEOF = "object";
41
42 var TIME = 0;
43 var UTC_YEAR = 1;
44 var UTC_MONTH = 2;
45 var UTC_DATE = 3;
46 var UTC_DAY = 4;
47 var UTC_HOURS = 5;
48 var UTC_MINUTES = 6;
49 var UTC_SECONDS = 7;
50 var UTC_MS = 8;
51
52 var YEAR = 9;
53 var MONTH = 10;
54 var DATE = 11;
55 var DAY = 12;
56 var HOURS = 13;
57 var MINUTES = 14;
58 var SECONDS = 15;
59 var MS = 16;
60
61
62 // for TCMS, the gTestcases array must be global.
63 var gTc= 0;
64 var TITLE = "Date constructor: new Date( value )";
65 var SECTION = "15.9.3.8";
66 var VERSION = "ECMA_1";
67 startTest();
68
69 writeHeaderToLog( SECTION +" " + TITLE );
70
71 // all the "ResultArrays" below are hard-coded to Pacific Standard Time values -
72 var TZ_ADJUST = -TZ_PST * msPerHour;
73
74
75 // Dates around 2000
76
77 addNewTestCase( new Date(TIME_2000+TZ_ADJUST),
78 "new Date(" +(TIME_2000+TZ_ADJUST)+")",
79 [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
80
81 addNewTestCase( new Date(TIME_2000),
82 "new Date(" +TIME_2000+")",
83 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
84
85 addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toString()),
86 "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toString()+"\")",
87 [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
88
89 addNewTestCase( new Date((new Date(TIME_2000)).toString()),
90 "new Date(\"" +(new Date(TIME_2000)).toString()+"\")",
91 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
92
93
94 addNewTestCase( new Date( (new Date(TIME_2000+TZ_ADJUST)).toUTCString()),
95 "new Date(\"" +(new Date(TIME_2000+TZ_ADJUST)).toUTCString()+"\")",
96 [TIME_2000+TZ_ADJUST,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
97
98 addNewTestCase( new Date( (new Date(TIME_2000)).toUTCString()),
99 "new Date(\"" +(new Date(TIME_2000)).toUTCString()+"\")",
100 [TIME_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
101
102 test();
103
104 function addNewTestCase( DateCase, DateString, ResultArray ) {
105 //adjust hard-coded ResultArray for tester's timezone instead of PST
106 adjustResultArray(ResultArray, 'msMode');
107
108 new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME], DateCase.getTime() );
109 new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME], DateCase.valueOf() );
110 new TestCase( SECTION, DateString+".getUTCFullYear()", ResultArray[UTC_YEAR], DateCase.getUTCFullYear() );
111 new TestCase( SECTION, DateString+".getUTCMonth()", ResultArray[UTC_MONTH], DateCase.getUTCMonth() );
112 new TestCase( SECTION, DateString+".getUTCDate()", ResultArray[UTC_DATE], DateCase.getUTCDate() );
113 new TestCase( SECTION, DateString+".getUTCDay()", ResultArray[UTC_DAY], DateCase.getUTCDay() );
114 new TestCase( SECTION, DateString+".getUTCHours()", ResultArray[UTC_HOURS], DateCase.getUTCHours() );
115 new TestCase( SECTION, DateString+".getUTCMinutes()", ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
116 new TestCase( SECTION, DateString+".getUTCSeconds()", ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
117 new TestCase( SECTION, DateString+".getUTCMilliseconds()", ResultArray[UTC_MS], DateCase.getUTCMilliseconds() );
118 new TestCase( SECTION, DateString+".getFullYear()", ResultArray[YEAR], DateCase.getFullYear() );
119 new TestCase( SECTION, DateString+".getMonth()", ResultArray[MONTH], DateCase.getMonth() );
120 new TestCase( SECTION, DateString+".getDate()", ResultArray[DATE], DateCase.getDate() );
121 new TestCase( SECTION, DateString+".getDay()", ResultArray[DAY], DateCase.getDay() );
122 new TestCase( SECTION, DateString+".getHours()", ResultArray[HOURS], DateCase.getHours() );
123 new TestCase( SECTION, DateString+".getMinutes()", ResultArray[MINUTES], DateCase.getMinutes() );
124 new TestCase( SECTION, DateString+".getSeconds()", ResultArray[SECONDS], DateCase.getSeconds() );
125 new TestCase( SECTION, DateString+".getMilliseconds()", ResultArray[MS], DateCase.getMilliseconds() );
126 }

mercurial