Debian Codegraph @

rhino/testsrc/tests/ecma/Date/15.9.3.8-2.js

raw symbols SCIP
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 gTestfile = '15.9.3.8-2.js';
7
8 /**
9 File Name: 15.9.3.8.js
10 ECMA Section: 15.9.3.8 The Date Constructor
11 new Date( value )
12 Description: The [[Prototype]] property of the newly constructed
13 object is set to the original Date prototype object,
14 the one that is the initial valiue of Date.prototype.
15
16 The [[Class]] property of the newly constructed object is
17 set to "Date".
18
19 The [[Value]] property of the newly constructed object is
20 set as follows:
21
22 1. Call ToPrimitive(value)
23 2. If Type( Result(1) ) is String, then go to step 5.
24 3. Let V be ToNumber( Result(1) ).
25 4. Set the [[Value]] property of the newly constructed
26 object to TimeClip(V) and return.
27 5. Parse Result(1) as a date, in exactly the same manner
28 as for the parse method. Let V be the time value for
29 this date.
30 6. Go to step 4.
31
32 Author: [email protected]
33 Date: 28 october 1997
34 Version: 9706
35
36 */
37
38 var VERSION = "ECMA_1";
39 startTest();
40 var SECTION = "15.9.3.8";
41 var TYPEOF = "object";
42
43 var TIME = 0;
44 var UTC_YEAR = 1;
45 var UTC_MONTH = 2;
46 var UTC_DATE = 3;
47 var UTC_DAY = 4;
48 var UTC_HOURS = 5;
49 var UTC_MINUTES = 6;
50 var UTC_SECONDS = 7;
51 var UTC_MS = 8;
52
53 var YEAR = 9;
54 var MONTH = 10;
55 var DATE = 11;
56 var DAY = 12;
57 var HOURS = 13;
58 var MINUTES = 14;
59 var SECONDS = 15;
60 var MS = 16;
61
62
63 // for TCMS, the gTestcases array must be global.
64 var gTc= 0;
65 var TITLE = "Date constructor: new Date( value )";
66 var SECTION = "15.9.3.8";
67 var VERSION = "ECMA_1";
68 startTest();
69
70 writeHeaderToLog( SECTION +" " + TITLE );
71
72 // all the "ResultArrays" below are hard-coded to Pacific Standard Time values -
73 var TZ_ADJUST = -TZ_PST * msPerHour;
74
75 addNewTestCase( new Date((new Date(0)).toUTCString()),
76 "new Date(\""+ (new Date(0)).toUTCString()+"\" )",
77 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
78
79 addNewTestCase( new Date((new Date(1)).toString()),
80 "new Date(\""+ (new Date(1)).toString()+"\" )",
81 [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
82
83 addNewTestCase( new Date( TZ_ADJUST ),
84 "new Date(" + TZ_ADJUST+")",
85 [TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
86
87 addNewTestCase( new Date((new Date(TZ_ADJUST)).toString()),
88 "new Date(\""+ (new Date(TZ_ADJUST)).toString()+"\")",
89 [TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
90
91
92 addNewTestCase( new Date( (new Date(TZ_ADJUST)).toUTCString() ),
93 "new Date(\""+ (new Date(TZ_ADJUST)).toUTCString()+"\")",
94 [TZ_ADJUST,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
95
96 test();
97
98 function addNewTestCase( DateCase, DateString, ResultArray ) {
99 //adjust hard-coded ResultArray for tester's timezone instead of PST
100 adjustResultArray(ResultArray, 'msMode');
101
102 new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME], DateCase.getTime() );
103 new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME], DateCase.valueOf() );
104 new TestCase( SECTION, DateString+".getUTCFullYear()", ResultArray[UTC_YEAR], DateCase.getUTCFullYear() );
105 new TestCase( SECTION, DateString+".getUTCMonth()", ResultArray[UTC_MONTH], DateCase.getUTCMonth() );
106 new TestCase( SECTION, DateString+".getUTCDate()", ResultArray[UTC_DATE], DateCase.getUTCDate() );
107 new TestCase( SECTION, DateString+".getUTCDay()", ResultArray[UTC_DAY], DateCase.getUTCDay() );
108 new TestCase( SECTION, DateString+".getUTCHours()", ResultArray[UTC_HOURS], DateCase.getUTCHours() );
109 new TestCase( SECTION, DateString+".getUTCMinutes()", ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
110 new TestCase( SECTION, DateString+".getUTCSeconds()", ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
111 new TestCase( SECTION, DateString+".getUTCMilliseconds()", ResultArray[UTC_MS], DateCase.getUTCMilliseconds() );
112 new TestCase( SECTION, DateString+".getFullYear()", ResultArray[YEAR], DateCase.getFullYear() );
113 new TestCase( SECTION, DateString+".getMonth()", ResultArray[MONTH], DateCase.getMonth() );
114 new TestCase( SECTION, DateString+".getDate()", ResultArray[DATE], DateCase.getDate() );
115 new TestCase( SECTION, DateString+".getDay()", ResultArray[DAY], DateCase.getDay() );
116 new TestCase( SECTION, DateString+".getHours()", ResultArray[HOURS], DateCase.getHours() );
117 new TestCase( SECTION, DateString+".getMinutes()", ResultArray[MINUTES], DateCase.getMinutes() );
118 new TestCase( SECTION, DateString+".getSeconds()", ResultArray[SECONDS], DateCase.getSeconds() );
119 new TestCase( SECTION, DateString+".getMilliseconds()", ResultArray[MS], DateCase.getMilliseconds() );
120 }