1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Date/15.9.5.28-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,163 @@ 1.4 +// |reftest| random-if(Android) 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.28-1.js 1.13 + ECMA Section: 15.9.5.28 Date.prototype.setMinutes(min [, sec [, ms ]] ) 1.14 + Description: 1.15 + If sec is not specified, this behaves as if sec were specified with the 1.16 + value getSeconds ( ). 1.17 + 1.18 + If ms is not specified, this behaves as if ms were specified with the 1.19 + value getMilliseconds( ). 1.20 + 1.21 + 1. Let t be the result of LocalTime(this time value). 1.22 + 2. Call ToNumber(min). 1.23 + 3. If sec is not specified, compute SecFromTime(t); otherwise, call ToNumber(sec). 1.24 + 4. If ms is not specified, compute msFromTime(t); otherwise, call ToNumber(ms). 1.25 + 5. Compute MakeTime(HourFromTime(t), Result(2), Result(3), Result(4)). 1.26 + 6. Compute UTC(MakeDate(Day(t), Result(5))). 1.27 + 7. Set the [[Value]] property of the this value to TimeClip(Result(6)). 1.28 + 8. Return the value of the [[Value]] property of the this value. 1.29 + 1.30 + Author: christine@netscape.com 1.31 + Date: 12 november 1997 1.32 +*/ 1.33 +var SECTION = "15.9.5.28-1"; 1.34 +var VERSION = "ECMA_1"; 1.35 +startTest(); 1.36 + 1.37 +writeHeaderToLog( SECTION + " Date.prototype.setMinutes(sec [,ms] )"); 1.38 + 1.39 +addNewTestCase( 0, 0, void 0, void 0, 1.40 + "TDATE = new Date(0);(TDATE).setMinutes(0);TDATE", 1.41 + UTCDateFromTime(SetMinutes(0,0,0,0)), 1.42 + LocalDateFromTime(SetMinutes(0,0,0,0)) ); 1.43 + 1.44 +addNewTestCase( 28800000, 59, 59, void 0, 1.45 + "TDATE = new Date(28800000);(TDATE).setMinutes(59,59);TDATE", 1.46 + UTCDateFromTime(SetMinutes(28800000,59,59)), 1.47 + LocalDateFromTime(SetMinutes(28800000,59,59)) ); 1.48 + 1.49 +addNewTestCase( 28800000, 59, 59, 999, 1.50 + "TDATE = new Date(28800000);(TDATE).setMinutes(59,59,999);TDATE", 1.51 + UTCDateFromTime(SetMinutes(28800000,59,59,999)), 1.52 + LocalDateFromTime(SetMinutes(28800000,59,59,999)) ); 1.53 + 1.54 +addNewTestCase( 28800000, 59, void 0, void 0, 1.55 + "TDATE = new Date(28800000);(TDATE).setMinutes(59);TDATE", 1.56 + UTCDateFromTime(SetMinutes(28800000,59,0)), 1.57 + LocalDateFromTime(SetMinutes(28800000,59,0)) ); 1.58 + 1.59 +addNewTestCase( 28800000, -480, void 0, void 0, 1.60 + "TDATE = new Date(28800000);(TDATE).setMinutes(-480);TDATE", 1.61 + UTCDateFromTime(SetMinutes(28800000,-480)), 1.62 + LocalDateFromTime(SetMinutes(28800000,-480)) ); 1.63 + 1.64 +addNewTestCase( 946684800000, 1234567, void 0, void 0, 1.65 + "TDATE = new Date(946684800000);(TDATE).setMinutes(1234567);TDATE", 1.66 + UTCDateFromTime(SetMinutes(946684800000,1234567)), 1.67 + LocalDateFromTime(SetMinutes(946684800000,1234567)) ); 1.68 + 1.69 +addNewTestCase( -2208988800000,59, 59, void 0, 1.70 + "TDATE = new Date(-2208988800000);(TDATE).setMinutes(59,59);TDATE", 1.71 + UTCDateFromTime(SetMinutes(-2208988800000,59,59)), 1.72 + LocalDateFromTime(SetMinutes(-2208988800000,59,59)) ); 1.73 + 1.74 +addNewTestCase( -2208988800000, 59, 59, 999, 1.75 + "TDATE = new Date(-2208988800000);(TDATE).setMinutes(59,59,999);TDATE", 1.76 + UTCDateFromTime(SetMinutes(-2208988800000,59,59,999)), 1.77 + LocalDateFromTime(SetMinutes(-2208988800000,59,59,999)) ); 1.78 + 1.79 +test(); 1.80 + 1.81 +function addNewTestCase( time, min, sec, ms, DateString, UTCDate, LocalDate) { 1.82 + DateCase = new Date( time ); 1.83 + 1.84 + if ( sec == void 0 ) { 1.85 + DateCase.setMinutes( min ); 1.86 + } else { 1.87 + if ( ms == void 0 ) { 1.88 + DateCase.setMinutes( min, sec ); 1.89 + } else { 1.90 + DateCase.setMinutes( min, sec, ms ); 1.91 + } 1.92 + } 1.93 + 1.94 + new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); 1.95 + new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); 1.96 + 1.97 + new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); 1.98 + new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); 1.99 + new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); 1.100 + 1.101 + new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); 1.102 + new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); 1.103 + new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); 1.104 + new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); 1.105 + 1.106 + new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); 1.107 + new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); 1.108 + new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); 1.109 + 1.110 + new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); 1.111 + new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); 1.112 + new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); 1.113 + new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); 1.114 + 1.115 + DateCase.toString = Object.prototype.toString; 1.116 + 1.117 + new TestCase( SECTION, 1.118 + DateString+".toString=Object.prototype.toString;"+DateString+".toString()", 1.119 + "[object Date]", 1.120 + DateCase.toString() ); 1.121 +} 1.122 + 1.123 +function MyDate() { 1.124 + this.year = 0; 1.125 + this.month = 0; 1.126 + this.date = 0; 1.127 + this.hours = 0; 1.128 + this.minutes = 0; 1.129 + this.seconds = 0; 1.130 + this.ms = 0; 1.131 +} 1.132 +function LocalDateFromTime(t) { 1.133 + t = LocalTime(t); 1.134 + return ( MyDateFromTime(t) ); 1.135 +} 1.136 +function UTCDateFromTime(t) { 1.137 + return ( MyDateFromTime(t) ); 1.138 +} 1.139 +function MyDateFromTime( t ) { 1.140 + var d = new MyDate(); 1.141 + d.year = YearFromTime(t); 1.142 + d.month = MonthFromTime(t); 1.143 + d.date = DateFromTime(t); 1.144 + d.hours = HourFromTime(t); 1.145 + d.minutes = MinFromTime(t); 1.146 + d.seconds = SecFromTime(t); 1.147 + d.ms = msFromTime(t); 1.148 + 1.149 + d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); 1.150 + d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); 1.151 + d.day = WeekDay( d.value ); 1.152 + 1.153 + return (d); 1.154 +} 1.155 + 1.156 +function SetMinutes( t, min, sec, ms ) { 1.157 + var TIME = LocalTime(t); 1.158 + var MIN = Number(min); 1.159 + var SEC = ( sec == void 0) ? SecFromTime(TIME) : Number(sec); 1.160 + var MS = ( ms == void 0 ) ? msFromTime(TIME) : Number(ms); 1.161 + var RESULT5 = MakeTime( HourFromTime( TIME ), 1.162 + MIN, 1.163 + SEC, 1.164 + MS ); 1.165 + return ( TimeClip(UTC( MakeDate(Day(TIME),RESULT5))) ); 1.166 +}