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