js/src/tests/ecma/Date/15.9.5.37-3.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 /**
     8    File Name:          15.9.5.37-1.js
     9    ECMA Section:       15.9.5.37 Date.prototype.setUTCFullYear(year [, mon [, date ]] )
    10    Description:
    12    If mon is not specified, this behaves as if mon were specified with the
    13    value getUTCMonth( ).  If date is not specified, this behaves as if date
    14    were specified with the value getUTCDate( ).
    16    1.   Let t be this time value; but if this time value is NaN, let t be +0.
    17    2.   Call ToNumber(year).
    18    3.   If mon is not specified, compute MonthFromTime(t); otherwise, call
    19    ToNumber(mon).
    20    4.   If date is not specified, compute DateFromTime(t); otherwise, call
    21    ToNumber(date).
    22    5.   Compute MakeDay(Result(2), Result(3), Result(4)).
    23    6.   Compute MakeDate(Result(5), TimeWithinDay(t)).
    24    7.   Set the [[Value]] property of the this value to TimeClip(Result(6)).
    25    8.   Return the value of the [[Value]] property of the this value.
    27    Author:             christine@netscape.com
    28    Date:               12 november 1997
    30    Added some Year 2000 test cases.
    31 */
    32 var SECTION = "15.9.5.37-1";
    33 var VERSION = "ECMA_1";
    34 startTest();
    36 writeHeaderToLog( SECTION + " Date.prototype.setUTCFullYear(year [, mon [, date ]] )");
    39 // Dates around 29 February 2000
    41 var UTC_FEB_29_1972 = TIME_1970 + TimeInYear(1970) + TimeInYear(1971) +
    42   31*msPerDay + 28*msPerDay;
    44 var PST_FEB_29_1972 = UTC_FEB_29_1972 - TZ_DIFF * msPerHour;
    46 addNewTestCase( "TDATE = new Date("+UTC_FEB_29_1972+"); "+
    47 		"TDATE.setUTCFullYear(2000);TDATE",
    48 		UTCDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)),
    49 		LocalDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)) );
    51 addNewTestCase( "TDATE = new Date("+PST_FEB_29_1972+"); "+
    52 		"TDATE.setUTCFullYear(2000);TDATE",
    53 		UTCDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)),
    54 		LocalDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)) );
    56 test();
    58 function addNewTestCase( DateString, UTCDate, LocalDate) {
    59   DateCase = eval( DateString );
    61   new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
    62   new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
    64   new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
    65   new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
    66   new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
    67   new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
    68   new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
    69   new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
    70   new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
    71   new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
    73   new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
    74   new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
    75   new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
    76   new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
    77   new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
    78   new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
    79   new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
    80   new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
    82   DateCase.toString = Object.prototype.toString;
    84   new TestCase( SECTION,
    85 		DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
    86 		"[object Date]",
    87 		DateCase.toString() );
    88 }
    90 function MyDate() {
    91   this.year = 0;
    92   this.month = 0;
    93   this.date = 0;
    94   this.hours = 0;
    95   this.minutes = 0;
    96   this.seconds = 0;
    97   this.ms = 0;
    98 }
    99 function LocalDateFromTime(t) {
   100   t = LocalTime(t);
   101   return ( MyDateFromTime(t) );
   102 }
   103 function UTCDateFromTime(t) {
   104   return ( MyDateFromTime(t) );
   105 }
   106 function MyDateFromTime( t ) {
   107   var d = new MyDate();
   108   d.year = YearFromTime(t);
   109   d.month = MonthFromTime(t);
   110   d.date = DateFromTime(t);
   111   d.hours = HourFromTime(t);
   112   d.minutes = MinFromTime(t);
   113   d.seconds = SecFromTime(t);
   114   d.ms = msFromTime(t);
   116   d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
   117   d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
   118   d.day = WeekDay( d.value );
   120   return (d);
   121 }
   122 function SetUTCFullYear( t, year, mon, date ) {
   123   var T = ( t != t ) ? 0 : t;
   124   var YEAR = Number(year);
   125   var MONTH = ( mon == void 0 ) ?     MonthFromTime(T) : Number( mon );
   126   var DATE  = ( date == void 0 ) ?    DateFromTime(T)  : Number( date );
   127   var DAY = MakeDay( YEAR, MONTH, DATE );
   129   return ( TimeClip(MakeDate(DAY, TimeWithinDay(T))) );
   130 }

mercurial