js/src/tests/ecma/Date/15.9.5.36-2.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Date/15.9.5.36-2.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.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-2";
    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 +// 1970
    1.44 +
    1.45 +addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1970);TDATE",
    1.46 +		UTCDateFromTime(SetFullYear(0,1970)),
    1.47 +		LocalDateFromTime(SetFullYear(0,1970)) );
    1.48 +
    1.49 +addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1970,0);TDATE",
    1.50 +		UTCDateFromTime(SetFullYear(0,1970,0)),
    1.51 +		LocalDateFromTime(SetFullYear(0,1970,0)) );
    1.52 +
    1.53 +addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(1970,0,1);TDATE",
    1.54 +		UTCDateFromTime(SetFullYear(0,1970,0,1)),
    1.55 +		LocalDateFromTime(SetFullYear(0,1970,0,1)) );
    1.56 +
    1.57 +test();
    1.58 +
    1.59 +function addNewTestCase( DateString, UTCDate, LocalDate) {
    1.60 +  DateCase = eval( DateString );
    1.61 +
    1.62 +  new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
    1.63 +  new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
    1.64 +
    1.65 +  new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
    1.66 +  new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
    1.67 +  new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
    1.68 +  new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
    1.69 +  new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
    1.70 +  new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
    1.71 +  new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
    1.72 +  new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
    1.73 +
    1.74 +  new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
    1.75 +  new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
    1.76 +  new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
    1.77 +  new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
    1.78 +  new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
    1.79 +  new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
    1.80 +  new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
    1.81 +  new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
    1.82 +
    1.83 +  DateCase.toString = Object.prototype.toString;
    1.84 +
    1.85 +  new TestCase( SECTION,
    1.86 +		DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
    1.87 +		"[object Date]",
    1.88 +		DateCase.toString() );
    1.89 +}
    1.90 +
    1.91 +function MyDate() {
    1.92 +  this.year = 0;
    1.93 +  this.month = 0;
    1.94 +  this.date = 0;
    1.95 +  this.hours = 0;
    1.96 +  this.minutes = 0;
    1.97 +  this.seconds = 0;
    1.98 +  this.ms = 0;
    1.99 +}
   1.100 +function LocalDateFromTime(t) {
   1.101 +  t = LocalTime(t);
   1.102 +  return ( MyDateFromTime(t) );
   1.103 +}
   1.104 +function UTCDateFromTime(t) {
   1.105 +  return ( MyDateFromTime(t) );
   1.106 +}
   1.107 +function MyDateFromTime( t ) {
   1.108 +  var d = new MyDate();
   1.109 +  d.year = YearFromTime(t);
   1.110 +  d.month = MonthFromTime(t);
   1.111 +  d.date = DateFromTime(t);
   1.112 +  d.hours = HourFromTime(t);
   1.113 +  d.minutes = MinFromTime(t);
   1.114 +  d.seconds = SecFromTime(t);
   1.115 +  d.ms = msFromTime(t);
   1.116 +
   1.117 +  d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
   1.118 +  d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
   1.119 +  d.day = WeekDay( d.value );
   1.120 +
   1.121 +  return (d);
   1.122 +}
   1.123 +function SetFullYear( t, year, mon, date ) {
   1.124 +  var T = ( isNaN(t) ) ? 0 : LocalTime(t) ;
   1.125 +  var YEAR = Number( year );
   1.126 +  var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon );
   1.127 +  var DATE = ( date == void 0 ) ? DateFromTime(T)  : Number( date );
   1.128 +
   1.129 +  var DAY = MakeDay( YEAR, MONTH, DATE );
   1.130 +  var UTC_DATE = UTC(MakeDate( DAY, TimeWithinDay(T)));
   1.131 +
   1.132 +  return ( TimeClip(UTC_DATE) );
   1.133 +}

mercurial