js/src/tests/ecma/Date/15.9.5.32-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.32-1.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     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.32-1.js
    1.12 +   ECMA Section:       15.9.5.32 Date.prototype.setDate(date)
    1.13 +   Description:
    1.14 +   1.  Let t be the result of LocalTime(this time value).
    1.15 +   2.  Call ToNumber(date).
    1.16 +   3.  Compute MakeDay(YearFromTime(t), MonthFromTime(t), Result(2)).
    1.17 +   4.  Compute UTC(MakeDate(Result(3), TimeWithinDay(t))).
    1.18 +   5.  Set the [[Value]] property of the this value to TimeClip(Result(4)).
    1.19 +   6.  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 +var SECTION = "15.9.5.32-1";
    1.25 +var VERSION = "ECMA_1";
    1.26 +startTest();
    1.27 +
    1.28 +writeHeaderToLog( SECTION + " Date.prototype.setDate(date) ");
    1.29 +
    1.30 +addNewTestCase( 0, 1,
    1.31 +		"TDATE = new Date(0);(TDATE).setDate(1);TDATE" );
    1.32 +
    1.33 +test();
    1.34 +
    1.35 +function addNewTestCase( t, d, DateString ) {
    1.36 +  var DateCase = new Date( t );
    1.37 +  DateCase.setDate( d );
    1.38 +
    1.39 +  var UTCDate = UTCDateFromTime(SetDate(t, d));
    1.40 +  var LocalDate=LocalDateFromTime(SetDate(t,d));
    1.41 +
    1.42 +
    1.43 +  new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
    1.44 +  new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
    1.45 +
    1.46 +  new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
    1.47 +  new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
    1.48 +  new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
    1.49 +  new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
    1.50 +  new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
    1.51 +  new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
    1.52 +  new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
    1.53 +  new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
    1.54 +
    1.55 +  new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
    1.56 +  new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
    1.57 +  new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
    1.58 +  new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
    1.59 +  new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
    1.60 +  new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
    1.61 +  new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
    1.62 +  new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
    1.63 +
    1.64 +  DateCase.toString = Object.prototype.toString;
    1.65 +
    1.66 +  new TestCase( SECTION,
    1.67 +		DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
    1.68 +		"[object Date]",
    1.69 +		DateCase.toString() );
    1.70 +}
    1.71 +function MyDate() {
    1.72 +  this.year = 0;
    1.73 +  this.month = 0;
    1.74 +  this.date = 0;
    1.75 +  this.hours = 0;
    1.76 +  this.minutes = 0;
    1.77 +  this.seconds = 0;
    1.78 +  this.ms = 0;
    1.79 +}
    1.80 +function LocalDateFromTime(t) {
    1.81 +  t = LocalTime(t);
    1.82 +  return ( MyDateFromTime(t) );
    1.83 +}
    1.84 +function UTCDateFromTime(t) {
    1.85 +  return ( MyDateFromTime(t) );
    1.86 +}
    1.87 +function MyDateFromTime( t ) {
    1.88 +  var d = new MyDate();
    1.89 +  d.year = YearFromTime(t);
    1.90 +  d.month = MonthFromTime(t);
    1.91 +  d.date = DateFromTime(t);
    1.92 +  d.hours = HourFromTime(t);
    1.93 +  d.minutes = MinFromTime(t);
    1.94 +  d.seconds = SecFromTime(t);
    1.95 +  d.ms = msFromTime(t);
    1.96 +
    1.97 +  d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
    1.98 +  d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
    1.99 +  d.day = WeekDay( d.value );
   1.100 +
   1.101 +  return (d);
   1.102 +}
   1.103 +
   1.104 +function SetDate( t, date ) {
   1.105 +  var T       = LocalTime( t );
   1.106 +  var DATE    = Number( date );
   1.107 +  var RESULT3 = MakeDay(YearFromTime(T), MonthFromTime(T), DATE );
   1.108 +  var UTC_DATE = UTC( MakeDate(RESULT3, TimeWithinDay(T)) );
   1.109 +  return ( TimeClip(UTC_DATE) );
   1.110 +}

mercurial