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/. */
8
File Name: 15.9.5.30-1.js
9
ECMA Section: 15.9.5.30 Date.prototype.setHours(hour [, min [, sec [, ms ]]] )
11
If min is not specified, this behaves as if min were specified with the
12
value getMinutes( ). If sec is not specified, this behaves as if sec were
13
specified with the value getSeconds ( ). If ms is not specified, this
14
behaves as if ms were specified with the value getMilliseconds( ).
16
1. Let t be the result of LocalTime(this time value).
17
2. Call ToNumber(hour).
18
3. If min is not specified, compute MinFromTime(t); otherwise, call
20
4. If sec is not specified, compute SecFromTime(t); otherwise, call
22
5. If ms is not specified, compute msFromTime(t); otherwise, call
24
6. Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
25
7. Compute UTC(MakeDate(Day(t), Result(6))).
26
8. Set the [[Value]] property of the this value to TimeClip(Result(7)).
27
9. Return the value of the [[Value]] property of the this value.
29
Author: christine@netscape.com
30
Date: 12 november 1997
32
var SECTION = "15.9.5.30-1";
33
var VERSION = "ECMA_1";
36
writeHeaderToLog( SECTION + " Date.prototype.setHours( hour [, min, sec, ms] )");
38
addNewTestCase( 0,0,0,0,void 0,
39
"TDATE = new Date(0);(TDATE).setHours(0);TDATE" );
41
addNewTestCase( 28800000, 23, 59, 999,void 0,
42
"TDATE = new Date(28800000);(TDATE).setHours(23,59,999);TDATE" );
44
addNewTestCase( 28800000, 999, 999, void 0, void 0,
45
"TDATE = new Date(28800000);(TDATE).setHours(999,999);TDATE" );
47
addNewTestCase( 28800000,999,0, void 0, void 0,
48
"TDATE = new Date(28800000);(TDATE).setHours(999);TDATE" );
50
addNewTestCase( 28800000,-8, void 0, void 0, void 0,
51
"TDATE = new Date(28800000);(TDATE).setHours(-8);TDATE" );
53
addNewTestCase( 946684800000,8760, void 0, void 0, void 0,
54
"TDATE = new Date(946684800000);(TDATE).setHours(8760);TDATE" );
56
addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 999,
57
"d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,999)" );
59
addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 1000,
60
"d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,1000)" );
64
function addNewTestCase( time, hours, min, sec, ms, DateString) {
65
var UTCDate = UTCDateFromTime( SetHours( time, hours, min, sec, ms ));
66
var LocalDate = LocalDateFromTime( SetHours( time, hours, min, sec, ms ));
68
var DateCase = new Date( time );
70
if ( min == void 0 ) {
71
DateCase.setHours( hours );
73
if ( sec == void 0 ) {
74
DateCase.setHours( hours, min );
77
DateCase.setHours( hours, min, sec );
79
DateCase.setHours( hours, min, sec, ms );
85
new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
86
new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
88
new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
89
new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
90
new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
91
new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
92
new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
93
new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
94
new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
95
new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
97
new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
98
new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
99
new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
100
new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
101
new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
102
new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
103
new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
104
new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
106
DateCase.toString = Object.prototype.toString;
108
new TestCase( SECTION,
109
DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
111
DateCase.toString() );
123
function LocalDateFromTime(t) {
125
return ( MyDateFromTime(t) );
127
function UTCDateFromTime(t) {
128
return ( MyDateFromTime(t) );
130
function MyDateFromTime( t ) {
131
var d = new MyDate();
132
d.year = YearFromTime(t);
133
d.month = MonthFromTime(t);
134
d.date = DateFromTime(t);
135
d.hours = HourFromTime(t);
136
d.minutes = MinFromTime(t);
137
d.seconds = SecFromTime(t);
138
d.ms = msFromTime(t);
140
d.day = WeekDay( t );
141
d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
142
d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
146
function SetHours( t, hour, min, sec, ms ) {
147
var TIME = LocalTime(t);
148
var HOUR = Number(hour);
149
var MIN = ( min == void 0) ? MinFromTime(TIME) : Number(min);
150
var SEC = ( sec == void 0) ? SecFromTime(TIME) : Number(sec);
151
var MS = ( ms == void 0 ) ? msFromTime(TIME) : Number(ms);
152
var RESULT6 = MakeTime( HOUR,
156
var UTC_TIME = UTC( MakeDate(Day(TIME), RESULT6) );
157
return ( TimeClip(UTC_TIME) );