js/src/tests/ecma/Date/15.9.5.23-18.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.23-18.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     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.23-1.js
    1.12 +   ECMA Section:       15.9.5.23 Date.prototype.setTime(time)
    1.13 +   Description:
    1.14 +
    1.15 +   1.  If the this value is not a Date object, generate a runtime error.
    1.16 +   2.  Call ToNumber(time).
    1.17 +   3.  Call TimeClip(Result(1)).
    1.18 +   4.  Set the [[Value]] property of the this value to Result(2).
    1.19 +   5.  Return the value of the [[Value]] property of the this value.
    1.20 +
    1.21 +   Author:             christine@netscape.com
    1.22 +   Date:               12 november 1997
    1.23 +
    1.24 +*/
    1.25 +var SECTION = "15.9.5.23-1";
    1.26 +var VERSION = "ECMA_1";
    1.27 +startTest();
    1.28 +var TITLE = "Date.prototype.setTime()";
    1.29 +
    1.30 +writeHeaderToLog( SECTION + " Date.prototype.setTime(time)");
    1.31 +
    1.32 +var now = "now";
    1.33 +addTestCase( now, String( TIME_2000 ) );
    1.34 +
    1.35 +test();
    1.36 +
    1.37 +function addTestCase( startTime, setTime ) {
    1.38 +  if ( startTime == "now" ) {
    1.39 +    DateCase = new Date();
    1.40 +  } else {
    1.41 +    DateCase = new Date( startTime );
    1.42 +  }
    1.43 +
    1.44 +  DateCase.setTime( setTime );
    1.45 +  var DateString = "var d = new Date("+startTime+"); d.setTime("+setTime+"); d" ;
    1.46 +  var UTCDate   = UTCDateFromTime ( Number(setTime) );
    1.47 +  var LocalDate = LocalDateFromTime( Number(setTime) );
    1.48 +
    1.49 +  new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,      DateCase.getTime() );
    1.50 +  new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,      DateCase.valueOf() );
    1.51 +
    1.52 +  new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,       DateCase.getUTCFullYear() );
    1.53 +  new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,      DateCase.getUTCMonth() );
    1.54 +  new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,       DateCase.getUTCDate() );
    1.55 +  new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,        DateCase.getUTCDay() );
    1.56 +  new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,      DateCase.getUTCHours() );
    1.57 +  new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,    DateCase.getUTCMinutes() );
    1.58 +  new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,    DateCase.getUTCSeconds() );
    1.59 +  new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,         DateCase.getUTCMilliseconds() );
    1.60 +
    1.61 +  new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,     DateCase.getFullYear() );
    1.62 +  new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,    DateCase.getMonth() );
    1.63 +  new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,     DateCase.getDate() );
    1.64 +  new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,      DateCase.getDay() );
    1.65 +  new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,    DateCase.getHours() );
    1.66 +  new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,  DateCase.getMinutes() );
    1.67 +  new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,  DateCase.getSeconds() );
    1.68 +  new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,       DateCase.getMilliseconds() );
    1.69 +
    1.70 +  DateCase.toString = Object.prototype.toString;
    1.71 +
    1.72 +  new TestCase( SECTION,
    1.73 +		DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
    1.74 +		"[object Date]",
    1.75 +		DateCase.toString() );
    1.76 +}
    1.77 +function MyDate() {
    1.78 +  this.year = 0;
    1.79 +  this.month = 0;
    1.80 +  this.date = 0;
    1.81 +  this.hours = 0;
    1.82 +  this.minutes = 0;
    1.83 +  this.seconds = 0;
    1.84 +  this.ms = 0;
    1.85 +}
    1.86 +function LocalDateFromTime(t) {
    1.87 +  t = LocalTime(t);
    1.88 +  return ( MyDateFromTime(t) );
    1.89 +}
    1.90 +function UTCDateFromTime(t) {
    1.91 +  return ( MyDateFromTime(t) );
    1.92 +}
    1.93 +function MyDateFromTime( t ) {
    1.94 +  var d       = new MyDate();
    1.95 +  d.year      = YearFromTime(t);
    1.96 +  d.month     = MonthFromTime(t);
    1.97 +  d.date      = DateFromTime(t);
    1.98 +  d.hours     = HourFromTime(t);
    1.99 +  d.minutes   = MinFromTime(t);
   1.100 +  d.seconds   = SecFromTime(t);
   1.101 +  d.ms        = msFromTime(t);
   1.102 +  d.time      = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
   1.103 +  d.value     = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
   1.104 +  d.day       = WeekDay( d.value );
   1.105 +  return (d);
   1.106 +}

mercurial