• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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@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
43    var testcases = new Array();
44    writeHeaderToLog( SECTION + " Date.prototype.setTime(time)");
45
46    getTestCases();
47    test();
48
49function getTestCases() {
50    var now = "now";
51    addTestCase( 0, 0 );
52/*
53    addTestCase( now, -2208988800000 );
54    addTestCase( now, -86400000 );
55    addTestCase( now, 946684800000 );
56
57    // this daylight savings case fails -- need to fix date test functions
58//    addTestCase( now, -69609600000 );
59    addTestCase( now, -2208988800000 );
60    addTestCase( now, 946684800000 );
61
62    // this daylight savings case fails -- need to fix date test functions
63//    addTestCase( now, -69609600000 );
64    addTestCase( now, 0 );
65    addTestCase( now, String( TIME_1900 ) );
66    addTestCase( now, String( TZ_DIFF* msPerHour ) );
67    addTestCase( now, String( TIME_2000 ) );
68*/
69}
70
71function addTestCase( startTime, setTime ) {
72    if ( startTime == "now" ) {
73        DateCase = new Date();
74    } else {
75        DateCase = new Date( startTime );
76    }
77
78    DateCase.setTime( setTime );
79    var DateString = "var d = new Date("+startTime+"); d.setTime("+setTime+"); d" ;
80    var UTCDate   = UTCDateFromTime ( Number(setTime) );
81    var LocalDate = LocalDateFromTime( Number(setTime) );
82    var item = testcases.length;
83
84//    fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
85
86    testcases[item++] = new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,      DateCase.getTime() );
87    testcases[item++] = new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,      DateCase.valueOf() );
88
89    testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,       DateCase.getUTCFullYear() );
90    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,      DateCase.getUTCMonth() );
91    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,       DateCase.getUTCDate() );
92    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,        DateCase.getUTCDay() );
93    testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,      DateCase.getUTCHours() );
94    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,    DateCase.getUTCMinutes() );
95    testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,    DateCase.getUTCSeconds() );
96    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,         DateCase.getUTCMilliseconds() );
97
98    testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,     DateCase.getFullYear() );
99    testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,    DateCase.getMonth() );
100    testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,     DateCase.getDate() );
101    testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,      DateCase.getDay() );
102    testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,    DateCase.getHours() );
103    testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,  DateCase.getMinutes() );
104    testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,  DateCase.getSeconds() );
105    testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,       DateCase.getMilliseconds() );
106
107    DateCase.toString = Object.prototype.toString;
108
109    testcases[item++] = new TestCase( SECTION,
110                                      DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
111                                      "[object Date]",
112                                      DateCase.toString() );
113}
114function MyDate() {
115    this.year = 0;
116    this.month = 0;
117    this.date = 0;
118    this.hours = 0;
119    this.minutes = 0;
120    this.seconds = 0;
121    this.ms = 0;
122}
123function LocalDateFromTime(t) {
124    t = LocalTime(t);
125    return ( MyDateFromTime(t) );
126}
127function UTCDateFromTime(t) {
128 return ( MyDateFromTime(t) );
129}
130function MyDateFromTime( t ) {
131    var d       = new MyDate();
132    d.year      = YearFromTime(t);
133    d.month     = MonthFromTime(t);
134    d.date      = DateFromTime(t);
135    d.hours     = HourFromTime(t);
136    d.minutes   = MinFromTime(t);
137    d.seconds   = SecFromTime(t);
138    d.ms        = msFromTime(t);
139    d.time      = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
140    d.value     = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
141    d.day       = WeekDay( d.value );
142    return (d);
143}
144
145function test() {
146    for ( tc=0; tc < testcases.length; tc++ ) {
147        testcases[tc].passed = writeTestCaseResult(
148                            testcases[tc].expect,
149                            testcases[tc].actual,
150                            testcases[tc].description +" = "+
151                            testcases[tc].actual );
152
153        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
154    }
155    stopTest();
156    return ( testcases );
157}
158