Debian Codegraph @

rhino/testsrc/tests/ecma/Date/15.9.5.30-1.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.5.30-1.js';
7
8 /**
9 File Name: 15.9.5.30-1.js
10 ECMA Section: 15.9.5.30 Date.prototype.setHours(hour [, min [, sec [, ms ]]] )
11 Description:
12 If min is not specified, this behaves as if min were specified with the
13 value getMinutes( ). If sec is not specified, this behaves as if sec were
14 specified with the value getSeconds ( ). If ms is not specified, this
15 behaves as if ms were specified with the value getMilliseconds( ).
16
17 1. Let t be the result of LocalTime(this time value).
18 2. Call ToNumber(hour).
19 3. If min is not specified, compute MinFromTime(t); otherwise, call
20 ToNumber(min).
21 4. If sec is not specified, compute SecFromTime(t); otherwise, call
22 ToNumber(sec).
23 5. If ms is not specified, compute msFromTime(t); otherwise, call
24 ToNumber(ms).
25 6. Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
26 7. Compute UTC(MakeDate(Day(t), Result(6))).
27 8. Set the [[Value]] property of the this value to TimeClip(Result(7)).
28 9. Return the value of the [[Value]] property of the this value.
29
30 Author: [email protected]
31 Date: 12 november 1997
32 */
33 var SECTION = "15.9.5.30-1";
34 var VERSION = "ECMA_1";
35 startTest();
36
37 writeHeaderToLog( SECTION + " Date.prototype.setHours( hour [, min, sec, ms] )");
38
39 addNewTestCase( 0,0,0,0,void 0,
40 "TDATE = new Date(0);(TDATE).setHours(0);TDATE" );
41
42 addNewTestCase( 28800000, 23, 59, 999,void 0,
43 "TDATE = new Date(28800000);(TDATE).setHours(23,59,999);TDATE" );
44
45 addNewTestCase( 28800000, 999, 999, void 0, void 0,
46 "TDATE = new Date(28800000);(TDATE).setHours(999,999);TDATE" );
47
48 addNewTestCase( 28800000,999,0, void 0, void 0,
49 "TDATE = new Date(28800000);(TDATE).setHours(999);TDATE" );
50
51 addNewTestCase( 28800000,-8, void 0, void 0, void 0,
52 "TDATE = new Date(28800000);(TDATE).setHours(-8);TDATE" );
53
54 addNewTestCase( 946684800000,8760, void 0, void 0, void 0,
55 "TDATE = new Date(946684800000);(TDATE).setHours(8760);TDATE" );
56
57 addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 999,
58 "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,999)" );
59
60 addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 1000,
61 "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,1000)" );
62
63 test();
64
65 function addNewTestCase( time, hours, min, sec, ms, DateString) {
66 var UTCDate = UTCDateFromTime( SetHours( time, hours, min, sec, ms ));
67 var LocalDate = LocalDateFromTime( SetHours( time, hours, min, sec, ms ));
68
69 var DateCase = new Date( time );
70
71 if ( min == void 0 ) {
72 DateCase.setHours( hours );
73 } else {
74 if ( sec == void 0 ) {
75 DateCase.setHours( hours, min );
76 } else {
77 if ( ms == void 0 ) {
78 DateCase.setHours( hours, min, sec );
79 } else {
80 DateCase.setHours( hours, min, sec, ms );
81 }
82 }
83 }
84
85
86 new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
87 new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
88
89 new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
90 new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
91 new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
92 new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
93 new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
94 new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
95 new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
96 new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
97
98 new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
99 new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
100 new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
101 new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
102 new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
103 new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
104 new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
105 new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
106
107 DateCase.toString = Object.prototype.toString;
108
109 new TestCase( SECTION,
110 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
111 "[object Date]",
112 DateCase.toString() );
113 }
114
115 function MyDate() {
116 this.year = 0;
117 this.month = 0;
118 this.date = 0;
119 this.hours = 0;
120 this.minutes = 0;
121 this.seconds = 0;
122 this.ms = 0;
123 }
124 function LocalDateFromTime(t) {
125 t = LocalTime(t);
126 return ( MyDateFromTime(t) );
127 }
128 function UTCDateFromTime(t) {
129 return ( MyDateFromTime(t) );
130 }
131 function MyDateFromTime( t ) {
132 var d = new MyDate();
133 d.year = YearFromTime(t);
134 d.month = MonthFromTime(t);
135 d.date = DateFromTime(t);
136 d.hours = HourFromTime(t);
137 d.minutes = MinFromTime(t);
138 d.seconds = SecFromTime(t);
139 d.ms = msFromTime(t);
140
141 d.day = WeekDay( t );
142 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
143 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
144
145 return (d);
146 }
147 function SetHours( t, hour, min, sec, ms ) {
148 var TIME = LocalTime(t);
149 var HOUR = Number(hour);
150 var MIN = ( min == void 0) ? MinFromTime(TIME) : Number(min);
151 var SEC = ( sec == void 0) ? SecFromTime(TIME) : Number(sec);
152 var MS = ( ms == void 0 ) ? msFromTime(TIME) : Number(ms);
153 var RESULT6 = MakeTime( HOUR,
154 MIN,
155 SEC,
156 MS );
157 var UTC_TIME = UTC( MakeDate(Day(TIME), RESULT6) );
158 return ( TimeClip(UTC_TIME) );
159 }