• 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.25-1.js
24    ECMA Section:       15.9.5.25 Date.prototype.setUTCMilliseconds(ms)
25    Description:
26        1.  Let t be this time value.
27        2.  Call ToNumber(ms).
28        3.  Compute MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), Result(2)).
29        4.  Compute MakeDate(Day(t), Result(3)).
30        5.  Set the [[Value]] property of the this value to TimeClip(Result(4)).
31        6.  Return the value of the [[Value]] property of the this value.
32    Author:             christine@netscape.com
33    Date:               12 november 1997
34*/
35    var SECTION = "15.9.5.25-1";
36    var VERSION = "ECMA_1";
37    startTest();
38
39    writeHeaderToLog( SECTION + " Date.prototype.setUTCMilliseconds(ms)");
40
41    var testcases = new Array();
42    getTestCases();
43    test();
44
45function test() {
46    for ( tc=0; tc < testcases.length; tc++ ) {
47        testcases[tc].passed = writeTestCaseResult(
48                            testcases[tc].expect,
49                            testcases[tc].actual,
50                            testcases[tc].description +" = "+
51                            testcases[tc].actual );
52
53        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
54    }
55    stopTest();
56    return ( testcases );
57}
58
59function getTestCases() {
60    addNewTestCase( 0, 0, "TDATE = new Date(0);(TDATE).setUTCMilliseconds(0);TDATE",
61                    UTCDateFromTime(SetUTCMilliseconds(0,0)),
62                    LocalDateFromTime(SetUTCMilliseconds(0,0)) );
63    addNewTestCase( 28800000,999,
64                    "TDATE = new Date(28800000);(TDATE).setUTCMilliseconds(999);TDATE",
65                    UTCDateFromTime(SetUTCMilliseconds(28800000,999)),
66                    LocalDateFromTime(SetUTCMilliseconds(28800000,999)) );
67    addNewTestCase( 28800000,-28800000,
68                    "TDATE = new Date(28800000);(TDATE).setUTCMilliseconds(-28800000);TDATE",
69                    UTCDateFromTime(SetUTCMilliseconds(28800000,-28800000)),
70                    LocalDateFromTime(SetUTCMilliseconds(28800000,-28800000)) );
71    addNewTestCase( 946684800000,1234567,
72                    "TDATE = new Date(946684800000);(TDATE).setUTCMilliseconds(1234567);TDATE",
73                    UTCDateFromTime(SetUTCMilliseconds(946684800000,1234567)),
74                    LocalDateFromTime(SetUTCMilliseconds(946684800000,1234567)) );
75    addNewTestCase( 946684800000, 123456789,
76                    "TDATE = new Date(946684800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
77                    UTCDateFromTime(SetUTCMilliseconds(946684800000,123456789)),
78                    LocalDateFromTime(SetUTCMilliseconds(946684800000,123456789)) );
79
80    addNewTestCase( -2208988800000,123456789,
81                    "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456789);TDATE",
82                    UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)),
83                    LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456789)) );
84
85    addNewTestCase( -2208988800000,123456,
86                    "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(123456);TDATE",
87                    UTCDateFromTime(SetUTCMilliseconds(-2208988800000,123456)),
88                    LocalDateFromTime(SetUTCMilliseconds(-2208988800000,123456)) );
89
90    addNewTestCase( -2208988800000,-123456,
91                    "TDATE = new Date(-2208988800000);(TDATE).setUTCMilliseconds(-123456);TDATE",
92                    UTCDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)),
93                    LocalDateFromTime(SetUTCMilliseconds(-2208988800000,-123456)) );
94
95    addNewTestCase( 0,-999,
96                    "TDATE = new Date(0);(TDATE).setUTCMilliseconds(-999);TDATE",
97                    UTCDateFromTime(SetUTCMilliseconds(0,-999)),
98                    LocalDateFromTime(SetUTCMilliseconds(0,-999)) );
99/*
100    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds(0);TEST_DATE",  UTCDateFromTime(0), LocalDateFromTime(0) );
101//    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds(-2208988800000);TEST_DATE",  UTCDateFromTime(-2208988800000), LocalDateFromTime(-2208988800000) );
102    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds(-86400000);TEST_DATE",  UTCDateFromTime(-86400000), LocalDateFromTime(-86400000) );
103    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds(946684800000);TEST_DATE",  UTCDateFromTime(946684800000), LocalDateFromTime(946684800000) );
104    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds(-69609600000);TEST_DATE",  UTCDateFromTime(-69609600000), LocalDateFromTime(-69609600000) );
105
106
107    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds('0');TEST_DATE",  UTCDateFromTime(0), LocalDateFromTime(0) );
108//    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds('-2208988800000');TEST_DATE",  UTCDateFromTime(-2208988800000), LocalDateFromTime(-2208988800000) );
109    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds('-86400000');TEST_DATE",  UTCDateFromTime(-86400000), LocalDateFromTime(-86400000) );
110    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds('946684800000');TEST_DATE",  UTCDateFromTime(946684800000), LocalDateFromTime(946684800000) );
111    addNewTestCase( "TEST_DATE = new Date(0);(TEST_DATE).setMilliseconds('-69609600000');TEST_DATE",  UTCDateFromTime(-69609600000), LocalDateFromTime(-69609600000) );
112*/
113}
114function addNewTestCase( initialTime, ms, DateString, UTCDate, LocalDate) {
115    DateCase = new Date(initialTime);
116    DateCase.setUTCMilliseconds(ms);
117
118    var item = testcases.length;
119
120//    fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
121
122    testcases[item++] = new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
123    testcases[item++] = new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
124
125    testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
126    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
127    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
128//    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
129    testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
130    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
131    testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
132    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
133
134    testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
135    testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
136    testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
137//    testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
138    testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
139    testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
140    testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
141    testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
142
143    DateCase.toString = Object.prototype.toString;
144
145    testcases[item++] = new TestCase( SECTION,
146                                      DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
147                                      "[object Date]",
148                                      DateCase.toString() );
149}
150function MyDate() {
151    this.year = 0;
152    this.month = 0;
153    this.date = 0;
154    this.hours = 0;
155    this.minutes = 0;
156    this.seconds = 0;
157    this.ms = 0;
158}
159function LocalDateFromTime(t) {
160    t = LocalTime(t);
161    return ( MyDateFromTime(t) );
162}
163function UTCDateFromTime(t) {
164 return ( MyDateFromTime(t) );
165}
166function MyDateFromTime( t ) {
167    var d = new MyDate();
168    d.year = YearFromTime(t);
169    d.month = MonthFromTime(t);
170    d.date = DateFromTime(t);
171    d.hours = HourFromTime(t);
172    d.minutes = MinFromTime(t);
173    d.seconds = SecFromTime(t);
174    d.ms = msFromTime(t);
175
176    d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
177    d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
178    d.day = WeekDay( d.value );
179
180    return (d);
181}
182
183function SetUTCMilliseconds( T, MS ) {
184    T = Number( T );
185    TIME = MakeTime(    HourFromTime(T),
186                        MinFromTime(T),
187                        SecFromTime(T),
188                        MS );
189    return( MakeDate( Day(T), TIME ));
190}
191