js/src/tests/ecma/Date/15.9.5.30-1.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.30-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,158 @@
     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.30-1.js
    1.12 +   ECMA Section:       15.9.5.30 Date.prototype.setHours(hour [, min [, sec [, ms ]]] )
    1.13 +   Description:
    1.14 +   If min is not specified, this behaves as if min were specified with the
    1.15 +   value getMinutes( ). If sec is not specified, this behaves as if sec were
    1.16 +   specified with the value getSeconds ( ). If ms is not specified, this
    1.17 +   behaves as if ms were specified with the value getMilliseconds( ).
    1.18 +
    1.19 +   1.  Let t be the result of LocalTime(this time value).
    1.20 +   2.  Call ToNumber(hour).
    1.21 +   3.  If min is not specified, compute MinFromTime(t); otherwise, call
    1.22 +   ToNumber(min).
    1.23 +   4.  If sec is not specified, compute SecFromTime(t); otherwise, call
    1.24 +   ToNumber(sec).
    1.25 +   5.  If ms is not specified, compute msFromTime(t); otherwise, call
    1.26 +   ToNumber(ms).
    1.27 +   6.  Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
    1.28 +   7.  Compute UTC(MakeDate(Day(t), Result(6))).
    1.29 +   8.  Set the [[Value]] property of the this value to TimeClip(Result(7)).
    1.30 +   9.  Return the value of the [[Value]] property of the this value.
    1.31 +
    1.32 +   Author:             christine@netscape.com
    1.33 +   Date:               12 november 1997
    1.34 +*/
    1.35 +var SECTION = "15.9.5.30-1";
    1.36 +var VERSION = "ECMA_1";
    1.37 +startTest();
    1.38 +
    1.39 +writeHeaderToLog( SECTION + " Date.prototype.setHours( hour [, min, sec, ms] )");
    1.40 +
    1.41 +addNewTestCase( 0,0,0,0,void 0,
    1.42 +		"TDATE = new Date(0);(TDATE).setHours(0);TDATE" );
    1.43 +
    1.44 +addNewTestCase( 28800000, 23, 59, 999,void 0,
    1.45 +		"TDATE = new Date(28800000);(TDATE).setHours(23,59,999);TDATE" );
    1.46 +
    1.47 +addNewTestCase( 28800000, 999, 999, void 0, void 0,
    1.48 +		"TDATE = new Date(28800000);(TDATE).setHours(999,999);TDATE" );
    1.49 +
    1.50 +addNewTestCase( 28800000,999,0, void 0, void 0,
    1.51 +		"TDATE = new Date(28800000);(TDATE).setHours(999);TDATE" );
    1.52 +
    1.53 +addNewTestCase( 28800000,-8, void 0, void 0, void 0,
    1.54 +		"TDATE = new Date(28800000);(TDATE).setHours(-8);TDATE" );
    1.55 +
    1.56 +addNewTestCase( 946684800000,8760, void 0, void 0, void 0,
    1.57 +                "TDATE = new Date(946684800000);(TDATE).setHours(8760);TDATE" );
    1.58 +
    1.59 +addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 999,
    1.60 +		"d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,999)" );
    1.61 +
    1.62 +addNewTestCase( TIME_2000 - msPerDay, 23, 59, 59, 1000,
    1.63 +		"d = new Date( " + (TIME_2000-msPerDay) +"); d.setHours(23,59,59,1000)" );
    1.64 +
    1.65 +test();
    1.66 +
    1.67 +function addNewTestCase( time, hours, min, sec, ms, DateString) {
    1.68 +  var UTCDate =   UTCDateFromTime( SetHours( time, hours, min, sec, ms ));
    1.69 +  var LocalDate = LocalDateFromTime( SetHours( time, hours, min, sec, ms ));
    1.70 +
    1.71 +  var DateCase = new Date( time );
    1.72 +
    1.73 +  if ( min == void 0 ) {
    1.74 +    DateCase.setHours( hours );
    1.75 +  } else {
    1.76 +    if ( sec == void 0 ) {
    1.77 +      DateCase.setHours( hours, min );
    1.78 +    } else {
    1.79 +      if ( ms == void 0 ) {
    1.80 +	DateCase.setHours( hours, min, sec );
    1.81 +      } else {
    1.82 +	DateCase.setHours( hours, min, sec, ms );
    1.83 +      }
    1.84 +    }
    1.85 +  }
    1.86 +
    1.87 +
    1.88 +  new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
    1.89 +  new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
    1.90 +
    1.91 +  new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
    1.92 +  new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
    1.93 +  new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
    1.94 +  new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
    1.95 +  new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
    1.96 +  new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
    1.97 +  new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
    1.98 +  new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
    1.99 +
   1.100 +  new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
   1.101 +  new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
   1.102 +  new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
   1.103 +  new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
   1.104 +  new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
   1.105 +  new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
   1.106 +  new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
   1.107 +  new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
   1.108 +
   1.109 +  DateCase.toString = Object.prototype.toString;
   1.110 +
   1.111 +  new TestCase( SECTION,
   1.112 +		DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
   1.113 +		"[object Date]",
   1.114 +		DateCase.toString() );
   1.115 +}
   1.116 +
   1.117 +function MyDate() {
   1.118 +  this.year = 0;
   1.119 +  this.month = 0;
   1.120 +  this.date = 0;
   1.121 +  this.hours = 0;
   1.122 +  this.minutes = 0;
   1.123 +  this.seconds = 0;
   1.124 +  this.ms = 0;
   1.125 +}
   1.126 +function LocalDateFromTime(t) {
   1.127 +  t = LocalTime(t);
   1.128 +  return ( MyDateFromTime(t) );
   1.129 +}
   1.130 +function UTCDateFromTime(t) {
   1.131 +  return ( MyDateFromTime(t) );
   1.132 +}
   1.133 +function MyDateFromTime( t ) {
   1.134 +  var d = new MyDate();
   1.135 +  d.year = YearFromTime(t);
   1.136 +  d.month = MonthFromTime(t);
   1.137 +  d.date = DateFromTime(t);
   1.138 +  d.hours = HourFromTime(t);
   1.139 +  d.minutes = MinFromTime(t);
   1.140 +  d.seconds = SecFromTime(t);
   1.141 +  d.ms = msFromTime(t);
   1.142 +
   1.143 +  d.day = WeekDay( t );
   1.144 +  d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
   1.145 +  d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
   1.146 +
   1.147 +  return (d);
   1.148 +}
   1.149 +function SetHours( t, hour, min, sec, ms ) {
   1.150 +  var TIME = LocalTime(t);
   1.151 +  var HOUR = Number(hour);
   1.152 +  var MIN =  ( min == void 0) ? MinFromTime(TIME) : Number(min);
   1.153 +  var SEC  = ( sec == void 0) ? SecFromTime(TIME) : Number(sec);
   1.154 +  var MS   = ( ms == void 0 ) ? msFromTime(TIME)  : Number(ms);
   1.155 +  var RESULT6 = MakeTime( HOUR,
   1.156 +			  MIN,
   1.157 +			  SEC,
   1.158 +			  MS );
   1.159 +  var UTC_TIME = UTC(  MakeDate(Day(TIME), RESULT6) );
   1.160 +  return ( TimeClip(UTC_TIME) );
   1.161 +}

mercurial