1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma/Date/15.9.5.37-3.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 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.37-1.js 1.12 + ECMA Section: 15.9.5.37 Date.prototype.setUTCFullYear(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 getUTCMonth( ). If date is not specified, this behaves as if date 1.17 + were specified with the value getUTCDate( ). 1.18 + 1.19 + 1. Let t be this time value; but if this time value is NaN, let t be +0. 1.20 + 2. Call ToNumber(year). 1.21 + 3. If mon is not specified, compute MonthFromTime(t); otherwise, call 1.22 + ToNumber(mon). 1.23 + 4. If date is not specified, compute DateFromTime(t); otherwise, call 1.24 + ToNumber(date). 1.25 + 5. Compute MakeDay(Result(2), Result(3), Result(4)). 1.26 + 6. Compute MakeDate(Result(5), TimeWithinDay(t)). 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 + Added some Year 2000 test cases. 1.34 +*/ 1.35 +var SECTION = "15.9.5.37-1"; 1.36 +var VERSION = "ECMA_1"; 1.37 +startTest(); 1.38 + 1.39 +writeHeaderToLog( SECTION + " Date.prototype.setUTCFullYear(year [, mon [, date ]] )"); 1.40 + 1.41 + 1.42 +// Dates around 29 February 2000 1.43 + 1.44 +var UTC_FEB_29_1972 = TIME_1970 + TimeInYear(1970) + TimeInYear(1971) + 1.45 + 31*msPerDay + 28*msPerDay; 1.46 + 1.47 +var PST_FEB_29_1972 = UTC_FEB_29_1972 - TZ_DIFF * msPerHour; 1.48 + 1.49 +addNewTestCase( "TDATE = new Date("+UTC_FEB_29_1972+"); "+ 1.50 + "TDATE.setUTCFullYear(2000);TDATE", 1.51 + UTCDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)), 1.52 + LocalDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)) ); 1.53 + 1.54 +addNewTestCase( "TDATE = new Date("+PST_FEB_29_1972+"); "+ 1.55 + "TDATE.setUTCFullYear(2000);TDATE", 1.56 + UTCDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)), 1.57 + LocalDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)) ); 1.58 + 1.59 +test(); 1.60 + 1.61 +function addNewTestCase( DateString, UTCDate, LocalDate) { 1.62 + DateCase = eval( DateString ); 1.63 + 1.64 + new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() ); 1.65 + new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() ); 1.66 + 1.67 + new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() ); 1.68 + new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() ); 1.69 + new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() ); 1.70 + new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() ); 1.71 + new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() ); 1.72 + new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() ); 1.73 + new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() ); 1.74 + new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() ); 1.75 + 1.76 + new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() ); 1.77 + new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() ); 1.78 + new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() ); 1.79 + new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() ); 1.80 + new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() ); 1.81 + new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() ); 1.82 + new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() ); 1.83 + new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() ); 1.84 + 1.85 + DateCase.toString = Object.prototype.toString; 1.86 + 1.87 + new TestCase( SECTION, 1.88 + DateString+".toString=Object.prototype.toString;"+DateString+".toString()", 1.89 + "[object Date]", 1.90 + DateCase.toString() ); 1.91 +} 1.92 + 1.93 +function MyDate() { 1.94 + this.year = 0; 1.95 + this.month = 0; 1.96 + this.date = 0; 1.97 + this.hours = 0; 1.98 + this.minutes = 0; 1.99 + this.seconds = 0; 1.100 + this.ms = 0; 1.101 +} 1.102 +function LocalDateFromTime(t) { 1.103 + t = LocalTime(t); 1.104 + return ( MyDateFromTime(t) ); 1.105 +} 1.106 +function UTCDateFromTime(t) { 1.107 + return ( MyDateFromTime(t) ); 1.108 +} 1.109 +function MyDateFromTime( t ) { 1.110 + var d = new MyDate(); 1.111 + d.year = YearFromTime(t); 1.112 + d.month = MonthFromTime(t); 1.113 + d.date = DateFromTime(t); 1.114 + d.hours = HourFromTime(t); 1.115 + d.minutes = MinFromTime(t); 1.116 + d.seconds = SecFromTime(t); 1.117 + d.ms = msFromTime(t); 1.118 + 1.119 + d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms ); 1.120 + d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) ); 1.121 + d.day = WeekDay( d.value ); 1.122 + 1.123 + return (d); 1.124 +} 1.125 +function SetUTCFullYear( t, year, mon, date ) { 1.126 + var T = ( t != t ) ? 0 : t; 1.127 + var YEAR = Number(year); 1.128 + var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon ); 1.129 + var DATE = ( date == void 0 ) ? DateFromTime(T) : Number( date ); 1.130 + var DAY = MakeDay( YEAR, MONTH, DATE ); 1.131 + 1.132 + return ( TimeClip(MakeDate(DAY, TimeWithinDay(T))) ); 1.133 +}