Home | History | Annotate | Download | only in Date
      1 /* The contents of this file are subject to the Netscape Public
      2  * License Version 1.1 (the "License"); you may not use this file
      3  * except in compliance with the License. You may obtain a copy of
      4  * the License at http://www.mozilla.org/NPL/
      5  *
      6  * Software distributed under the License is distributed on an "AS
      7  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
      8  * implied. See the License for the specific language governing
      9  * rights and limitations under the License.
     10  *
     11  * The Original Code is Mozilla Communicator client code, released March
     12  * 31, 1998.
     13  *
     14  * The Initial Developer of the Original Code is Netscape Communications
     15  * Corporation. Portions created by Netscape are
     16  * Copyright (C) 1998 Netscape Communications Corporation. All
     17  * Rights Reserved.
     18  *
     19  * Contributor(s):
     20  *
     21  */
     22 /**
     23     File Name:          15.9.5.23-1.js
     24     ECMA Section:       15.9.5.23 Date.prototype.setTime(time)
     25     Description:
     26 
     27     1.  If the this value is not a Date object, generate a runtime error.
     28     2.  Call ToNumber(time).
     29     3.  Call TimeClip(Result(1)).
     30     4.  Set the [[Value]] property of the this value to Result(2).
     31     5.  Return the value of the [[Value]] property of the this value.
     32 
     33     Author:             christine (at) netscape.com
     34     Date:               12 november 1997
     35 
     36 */
     37     var SECTION = "15.9.5.23-1";
     38     var VERSION = "ECMA_1";
     39     startTest();
     40     var TITLE = "Date.prototype.setTime()";
     41 
     42     writeHeaderToLog( SECTION + " Date.prototype.setTime(time)");
     43 
     44     var testcases = new Array();
     45     getTestCases();
     46     test();
     47 
     48 function getTestCases() {
     49     var now = "now";
     50     addTestCase( now, String( TZ_DIFF* msPerHour ) );
     51 /*
     52     addTestCase( now, String( TIME_2000 ) );
     53 */
     54 }
     55 
     56 function addTestCase( startTime, setTime ) {
     57     if ( startTime == "now" ) {
     58         DateCase = new Date();
     59     } else {
     60         DateCase = new Date( startTime );
     61     }
     62 
     63     DateCase.setTime( setTime );
     64     var DateString = "var d = new Date("+startTime+"); d.setTime("+setTime+"); d" ;
     65     var UTCDate   = UTCDateFromTime ( Number(setTime) );
     66     var LocalDate = LocalDateFromTime( Number(setTime) );
     67     var item = testcases.length;
     68 
     69 //    fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
     70 
     71     testcases[item++] = new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,      DateCase.getTime() );
     72     testcases[item++] = new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,      DateCase.valueOf() );
     73 
     74     testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,       DateCase.getUTCFullYear() );
     75     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,      DateCase.getUTCMonth() );
     76     testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,       DateCase.getUTCDate() );
     77     testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,        DateCase.getUTCDay() );
     78     testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,      DateCase.getUTCHours() );
     79     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,    DateCase.getUTCMinutes() );
     80     testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,    DateCase.getUTCSeconds() );
     81     testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,         DateCase.getUTCMilliseconds() );
     82 
     83     testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,     DateCase.getFullYear() );
     84     testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,    DateCase.getMonth() );
     85     testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,     DateCase.getDate() );
     86     testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,      DateCase.getDay() );
     87     testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,    DateCase.getHours() );
     88     testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,  DateCase.getMinutes() );
     89     testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,  DateCase.getSeconds() );
     90     testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,       DateCase.getMilliseconds() );
     91 
     92     DateCase.toString = Object.prototype.toString;
     93 
     94     testcases[item++] = new TestCase( SECTION,
     95                                       DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
     96                                       "[object Date]",
     97                                       DateCase.toString() );
     98 }
     99 function MyDate() {
    100     this.year = 0;
    101     this.month = 0;
    102     this.date = 0;
    103     this.hours = 0;
    104     this.minutes = 0;
    105     this.seconds = 0;
    106     this.ms = 0;
    107 }
    108 function LocalDateFromTime(t) {
    109     t = LocalTime(t);
    110     return ( MyDateFromTime(t) );
    111 }
    112 function UTCDateFromTime(t) {
    113  return ( MyDateFromTime(t) );
    114 }
    115 function MyDateFromTime( t ) {
    116     var d       = new MyDate();
    117     d.year      = YearFromTime(t);
    118     d.month     = MonthFromTime(t);
    119     d.date      = DateFromTime(t);
    120     d.hours     = HourFromTime(t);
    121     d.minutes   = MinFromTime(t);
    122     d.seconds   = SecFromTime(t);
    123     d.ms        = msFromTime(t);
    124     d.time      = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
    125     d.value     = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
    126     d.day       = WeekDay( d.value );
    127     return (d);
    128 }
    129 
    130 function test() {
    131     for ( tc=0; tc < testcases.length; tc++ ) {
    132         testcases[tc].passed = writeTestCaseResult(
    133                             testcases[tc].expect,
    134                             testcases[tc].actual,
    135                             testcases[tc].description +" = "+
    136                             testcases[tc].actual );
    137 
    138         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
    139     }
    140     stopTest();
    141     return ( testcases );
    142 }
    143