michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 15.9.5.30-1.js michael@0: ECMA Section: 15.9.5.30 Date.prototype.setHours(hour [, min [, sec [, ms ]]] ) michael@0: Description: michael@0: If min is not specified, this behaves as if min were specified with the michael@0: value getMinutes( ). If sec is not specified, this behaves as if sec were michael@0: specified with the value getSeconds ( ). If ms is not specified, this michael@0: behaves as if ms were specified with the value getMilliseconds( ). michael@0: michael@0: 1. Let t be the result of LocalTime(this time value). michael@0: 2. Call ToNumber(hour). michael@0: 3. If min is not specified, compute MinFromTime(t); otherwise, call michael@0: ToNumber(min). michael@0: 4. If sec is not specified, compute SecFromTime(t); otherwise, call michael@0: ToNumber(sec). michael@0: 5. If ms is not specified, compute msFromTime(t); otherwise, call michael@0: ToNumber(ms). michael@0: 6. Compute MakeTime(Result(2), Result(3), Result(4), Result(5)). michael@0: 7. Compute UTC(MakeDate(Day(t), Result(6))). michael@0: 8. Set the [[Value]] property of the this value to TimeClip(Result(7)). michael@0: 9. Return the value of the [[Value]] property of the this value. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: var SECTION = "15.9.5.30-1"; michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: michael@0: writeHeaderToLog( SECTION + " Date.prototype.setHours( hour [, min, sec, ms] )"); michael@0: michael@0: addNewTestCase( 0,0,0,0,void 0, michael@0: "TDATE = new Date(0);(TDATE).setHours(0);TDATE" ); michael@0: michael@0: addNewTestCase( 28800000, 23, 59, 999,void 0, michael@0: "TDATE = new Date(28800000);(TDATE).setHours(23,59,999);TDATE" ); michael@0: michael@0: addNewTestCase( 28800000, 999, 999, void 0, void 0, michael@0: "TDATE = new Date(28800000);(TDATE).setHours(999,999);TDATE" ); michael@0: michael@0: addNewTestCase( 28800000,999,0, void 0, void 0, michael@0: "TDATE = new Date(28800000);(TDATE).setHours(999);TDATE" ); michael@0: michael@0: addNewTestCase( 28800000,-8, void 0, void 0, void 0, michael@0: "TDATE = new Date(28800000);(TDATE).setHours(-8);TDATE" ); michael@0: michael@0: addNewTestCase( 946684800000,8760, void 0, void 0, void 0, michael@0: "TDATE = new Date(946684800000);(TDATE).setHours(8760);TDATE" ); michael@0: michael@0: addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 999, michael@0: "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,999)" ); michael@0: michael@0: addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 1000, michael@0: "d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,1000)" ); michael@0: michael@0: test(); michael@0: michael@0: function addNewTestCase( time, hours, min, sec, ms, DateString) { michael@0: var UTCDate = UTCDateFromTime( SetHours( time, hours, min, sec, ms )); michael@0: var LocalDate = LocalDateFromTime( SetHours( time, hours, min, sec, ms )); michael@0: michael@0: var DateCase = new Date( time ); michael@0: michael@0: if ( min == void 0 ) { michael@0: DateCase.setHours( hours ); michael@0: } else { michael@0: if ( sec == void 0 ) { michael@0: DateCase.setHours( hours, min ); michael@0: } else { michael@0: if ( ms == void 0 ) { michael@0: DateCase.setHours( hours, min, sec ); michael@0: } else { michael@0: DateCase.setHours( hours, min, sec, ms ); michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); michael@0: new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); michael@0: michael@0: new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); michael@0: new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); michael@0: new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); michael@0: new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() ); michael@0: new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); michael@0: new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); michael@0: new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); michael@0: new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); michael@0: michael@0: new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); michael@0: new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); michael@0: new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); michael@0: new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() ); michael@0: new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); michael@0: new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); michael@0: new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); michael@0: new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); michael@0: michael@0: DateCase.toString = Object.prototype.toString; michael@0: michael@0: new TestCase( SECTION, michael@0: DateString+".toString=Object.prototype.toString;"+DateString+".toString()", michael@0: "[object Date]", michael@0: DateCase.toString() ); michael@0: } michael@0: michael@0: function MyDate() { michael@0: this.year = 0; michael@0: this.month = 0; michael@0: this.date = 0; michael@0: this.hours = 0; michael@0: this.minutes = 0; michael@0: this.seconds = 0; michael@0: this.ms = 0; michael@0: } michael@0: function LocalDateFromTime(t) { michael@0: t = LocalTime(t); michael@0: return ( MyDateFromTime(t) ); michael@0: } michael@0: function UTCDateFromTime(t) { michael@0: return ( MyDateFromTime(t) ); michael@0: } michael@0: function MyDateFromTime( t ) { michael@0: var d = new MyDate(); michael@0: d.year = YearFromTime(t); michael@0: d.month = MonthFromTime(t); michael@0: d.date = DateFromTime(t); michael@0: d.hours = HourFromTime(t); michael@0: d.minutes = MinFromTime(t); michael@0: d.seconds = SecFromTime(t); michael@0: d.ms = msFromTime(t); michael@0: michael@0: d.day = WeekDay( t ); michael@0: d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); michael@0: d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); michael@0: michael@0: return (d); michael@0: } michael@0: function SetHours( t, hour, min, sec, ms ) { michael@0: var TIME = LocalTime(t); michael@0: var HOUR = Number(hour); michael@0: var MIN = ( min == void 0) ? MinFromTime(TIME) : Number(min); michael@0: var SEC = ( sec == void 0) ? SecFromTime(TIME) : Number(sec); michael@0: var MS = ( ms == void 0 ) ? msFromTime(TIME) : Number(ms); michael@0: var RESULT6 = MakeTime( HOUR, michael@0: MIN, michael@0: SEC, michael@0: MS ); michael@0: var UTC_TIME = UTC( MakeDate(Day(TIME), RESULT6) ); michael@0: return ( TimeClip(UTC_TIME) ); michael@0: }