1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Date/15.9.5.34-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 +// |reftest| random 1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 +/** 1.12 + File Name: 15.9.5.34-1.js 1.13 + ECMA Section: 15.9.5.34 Date.prototype.setMonth(mon [, date ] ) 1.14 + Description: 1.15 + If date is not specified, this behaves as if date were specified with the 1.16 + value getDate( ). 1.17 + 1.18 + 1. Let t be the result of LocalTime(this time value). 1.19 + 2. Call ToNumber(date). 1.20 + 3. If date is not specified, compute DateFromTime(t); otherwise, call ToNumber(date). 1.21 + 4. Compute MakeDay(YearFromTime(t), Result(2), Result(3)). 1.22 + 5. Compute UTC(MakeDate(Result(4), TimeWithinDay(t))). 1.23 + 6. Set the [[Value]] property of the this value to TimeClip(Result(5)). 1.24 + 7. Return the value of the [[Value]] property of the this value. 1.25 + 1.26 + Author: christine@netscape.com 1.27 + Date: 12 november 1997 1.28 +*/ 1.29 +var SECTION = "15.9.5.34-1"; 1.30 +var VERSION = "ECMA_1"; 1.31 +startTest(); 1.32 + 1.33 +writeHeaderToLog( SECTION + " Date.prototype.setMonth(mon [, date ] )"); 1.34 + 1.35 +getFunctionCases(); 1.36 + 1.37 +// regression test for http://scopus.mcom.com/bugsplat/show_bug.cgi?id=112404 1.38 +d = new Date(0); 1.39 +d.setMonth(1,1,1,1,1,1); 1.40 + 1.41 +addNewTestCase( 1.42 + "TDATE = new Date(0); TDATE.setMonth(1,1,1,1,1,1); TDATE", 1.43 + UTCDateFromTime(SetMonth(0,1,1)), 1.44 + LocalDateFromTime(SetMonth(0,1,1)) ); 1.45 + 1.46 + 1.47 +// whatever today is 1.48 + 1.49 +addNewTestCase( "TDATE = new Date(TIME_NOW); (TDATE).setMonth(11,31); TDATE", 1.50 + UTCDateFromTime(SetMonth(TIME_NOW,11,31)), 1.51 + LocalDateFromTime(SetMonth(TIME_NOW,11,31)) ); 1.52 + 1.53 +// 1970 1.54 + 1.55 +addNewTestCase( "TDATE = new Date(0);(TDATE).setMonth(0,1);TDATE", 1.56 + UTCDateFromTime(SetMonth(0,0,1)), 1.57 + LocalDateFromTime(SetMonth(0,0,1)) ); 1.58 + 1.59 +addNewTestCase( "TDATE = new Date("+TIME_1900+"); "+ 1.60 + "(TDATE).setMonth(11,31); TDATE", 1.61 + UTCDateFromTime( SetMonth(TIME_1900,11,31) ), 1.62 + LocalDateFromTime( SetMonth(TIME_1900,11,31) ) ); 1.63 + 1.64 +test(); 1.65 + 1.66 +function addNewTestCase( DateString, UTCDate, LocalDate) { 1.67 + DateCase = eval( DateString ); 1.68 + 1.69 + new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); 1.70 + new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); 1.71 + 1.72 + new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); 1.73 + new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); 1.74 + new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); 1.75 + new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() ); 1.76 + new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); 1.77 + new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); 1.78 + new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); 1.79 + new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); 1.80 + 1.81 + new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); 1.82 + new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); 1.83 + new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); 1.84 + new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() ); 1.85 + new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); 1.86 + new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); 1.87 + new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); 1.88 + new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); 1.89 + 1.90 + DateCase.toString = Object.prototype.toString; 1.91 + 1.92 + new TestCase( SECTION, 1.93 + DateString+".toString=Object.prototype.toString;"+DateString+".toString()", 1.94 + "[object Date]", 1.95 + DateCase.toString() ); 1.96 +} 1.97 + 1.98 +function getFunctionCases() { 1.99 + // some tests for all functions 1.100 + new TestCase( 1.101 + SECTION, 1.102 + "Date.prototype.setMonth.length", 1.103 + 2, 1.104 + Date.prototype.setMonth.length ); 1.105 + 1.106 + new TestCase( 1.107 + SECTION, 1.108 + "typeof Date.prototype.setMonth", 1.109 + "function", 1.110 + typeof Date.prototype.setMonth ); 1.111 + 1.112 +} 1.113 + 1.114 +function MyDate() { 1.115 + this.year = 0; 1.116 + this.month = 0; 1.117 + this.date = 0; 1.118 + this.hours = 0; 1.119 + this.minutes = 0; 1.120 + this.seconds = 0; 1.121 + this.ms = 0; 1.122 +} 1.123 +function LocalDateFromTime(t) { 1.124 + t = LocalTime(t); 1.125 + return ( MyDateFromTime(t) ); 1.126 +} 1.127 +function UTCDateFromTime(t) { 1.128 + return ( MyDateFromTime(t) ); 1.129 +} 1.130 +function MyDateFromTime( t ) { 1.131 + var d = new MyDate(); 1.132 + d.year = YearFromTime(t); 1.133 + d.month = MonthFromTime(t); 1.134 + d.date = DateFromTime(t); 1.135 + d.hours = HourFromTime(t); 1.136 + d.minutes = MinFromTime(t); 1.137 + d.seconds = SecFromTime(t); 1.138 + d.ms = msFromTime(t); 1.139 + 1.140 + d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); 1.141 + d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); 1.142 + d.day = WeekDay( d.value ); 1.143 + 1.144 + return (d); 1.145 +} 1.146 +function SetMonth( t, mon, date ) { 1.147 + var TIME = LocalTime(t); 1.148 + var MONTH = Number( mon ); 1.149 + var DATE = ( date == void 0 ) ? DateFromTime(TIME) : Number( date ); 1.150 + var DAY = MakeDay( YearFromTime(TIME), MONTH, DATE ); 1.151 + return ( TimeClip (UTC(MakeDate( DAY, TimeWithinDay(TIME) ))) ); 1.152 +}