js/src/tests/ecma/Date/15.9.5.27-1.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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.27-1.js
     9    ECMA Section:       15.9.5.27 Date.prototype.setUTCSeconds(sec [,ms])
    10    Description:
    12    If ms is not specified, this behaves as if ms were specified with the
    13    value getUTCMilliseconds( ).
    15    1.  Let t be this time value.
    16    2.  Call ToNumber(sec).
    17    3.  If ms is not specified, compute msFromTime(t); otherwise, call
    18    ToNumber(ms)
    19    4.  Compute MakeTime(HourFromTime(t), MinFromTime(t), Result(2), Result(3))
    20    5.  Compute MakeDate(Day(t), Result(4)).
    21    6.  Set the [[Value]] property of the this value to TimeClip(Result(5)).
    22    7.  Return the value of the [[Value]] property of the this value.
    24    Author:             christine@netscape.com
    25    Date:               12 november 1997
    26 */
    27 var SECTION = "15.9.5.27-1";
    28 var VERSION = "ECMA_1";
    29 startTest();
    31 writeHeaderToLog( SECTION + " Date.prototype.setUTCSeconds(sec [,ms] )");
    33 addNewTestCase( 0, 0, 0, "TDATE = new Date(0);(TDATE).setUTCSeconds(0,0);TDATE",
    34 		UTCDateFromTime(SetUTCSeconds(0,0,0)),
    35 		LocalDateFromTime(SetUTCSeconds(0,0,0)) );
    37 addNewTestCase( 28800000,59,999,
    38 		"TDATE = new Date(28800000);(TDATE).setUTCSeconds(59,999);TDATE",
    39 		UTCDateFromTime(SetUTCSeconds(28800000,59,999)),
    40 		LocalDateFromTime(SetUTCSeconds(28800000,59,999)) );
    42 addNewTestCase( 28800000,999,999,
    43 		"TDATE = new Date(28800000);(TDATE).setUTCSeconds(999,999);TDATE",
    44 		UTCDateFromTime(SetUTCSeconds(28800000,999,999)),
    45 		LocalDateFromTime(SetUTCSeconds(28800000,999,999)) );
    47 addNewTestCase( 28800000, 999, void 0,
    48 		"TDATE = new Date(28800000);(TDATE).setUTCSeconds(999);TDATE",
    49 		UTCDateFromTime(SetUTCSeconds(28800000,999,0)),
    50 		LocalDateFromTime(SetUTCSeconds(28800000,999,0)) );
    52 addNewTestCase( 28800000, -28800, void 0,
    53 		"TDATE = new Date(28800000);(TDATE).setUTCSeconds(-28800);TDATE",
    54 		UTCDateFromTime(SetUTCSeconds(28800000,-28800)),
    55 		LocalDateFromTime(SetUTCSeconds(28800000,-28800)) );
    57 addNewTestCase( 946684800000, 1234567, void 0,
    58 		"TDATE = new Date(946684800000);(TDATE).setUTCSeconds(1234567);TDATE",
    59 		UTCDateFromTime(SetUTCSeconds(946684800000,1234567)),
    60 		LocalDateFromTime(SetUTCSeconds(946684800000,1234567)) );
    62 addNewTestCase( -2208988800000,59,999,
    63 		"TDATE = new Date(-2208988800000);(TDATE).setUTCSeconds(59,999);TDATE",
    64 		UTCDateFromTime(SetUTCSeconds(-2208988800000,59,999)),
    65 		LocalDateFromTime(SetUTCSeconds(-2208988800000,59,999)) );
    67 test();
    69 function addNewTestCase( startTime, sec, ms, DateString, UTCDate, LocalDate) {
    70   DateCase = new Date( startTime );
    71   if ( ms == void 0) {
    72     DateCase.setSeconds( sec );
    73   } else {
    74     DateCase.setSeconds( sec, ms );
    75   }
    77   new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
    78   new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
    80   new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
    81   new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
    82   new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
    84   new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
    85   new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
    86   new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
    87   new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
    89   new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
    90   new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
    91   new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
    93   new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
    94   new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
    95   new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
    96   new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
    98   DateCase.toString = Object.prototype.toString;
   100   new TestCase( SECTION,
   101 		DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
   102 		"[object Date]",
   103 		DateCase.toString() );
   104 }
   106 function MyDate() {
   107   this.year = 0;
   108   this.month = 0;
   109   this.date = 0;
   110   this.hours = 0;
   111   this.minutes = 0;
   112   this.seconds = 0;
   113   this.ms = 0;
   114 }
   115 function LocalDateFromTime(t) {
   116   t = LocalTime(t);
   117   return ( MyDateFromTime(t) );
   118 }
   119 function UTCDateFromTime(t) {
   120   return ( MyDateFromTime(t) );
   121 }
   122 function MyDateFromTime( t ) {
   123   var d = new MyDate();
   124   d.year = YearFromTime(t);
   125   d.month = MonthFromTime(t);
   126   d.date = DateFromTime(t);
   127   d.hours = HourFromTime(t);
   128   d.minutes = MinFromTime(t);
   129   d.seconds = SecFromTime(t);
   130   d.ms = msFromTime(t);
   132   d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
   133   d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
   134   d.day = WeekDay( d.value );
   136   return (d);
   137 }
   139 function SetUTCSeconds( t, s, m ) {
   140   var TIME = t;
   141   var SEC  = Number(s);
   142   var MS   = ( m == void 0 ) ? msFromTime(TIME) : Number( m );
   143   var RESULT4 = MakeTime( HourFromTime( TIME ),
   144 			  MinFromTime( TIME ),
   145 			  SEC,
   146 			  MS );
   147   return ( TimeClip(MakeDate(Day(TIME), RESULT4)) );
   148 }

mercurial