js/src/tests/ecma/Date/15.9.5.23-15.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:fd72073c6833
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
7 /**
8 File Name: 15.9.5.23-1.js
9 ECMA Section: 15.9.5.23 Date.prototype.setTime(time)
10 Description:
11
12 1. If the this value is not a Date object, generate a runtime error.
13 2. Call ToNumber(time).
14 3. Call TimeClip(Result(1)).
15 4. Set the [[Value]] property of the this value to Result(2).
16 5. Return the value of the [[Value]] property of the this value.
17
18 Author: christine@netscape.com
19 Date: 12 november 1997
20
21 */
22 var SECTION = "15.9.5.23-1";
23 var VERSION = "ECMA_1";
24 startTest();
25 var TITLE = "Date.prototype.setTime()";
26
27 writeHeaderToLog( SECTION + " Date.prototype.setTime(time)");
28
29 var now = "now";
30 addTestCase( now, 0 );
31
32 test();
33
34 function addTestCase( startTime, setTime ) {
35 if ( startTime == "now" ) {
36 DateCase = new Date();
37 } else {
38 DateCase = new Date( startTime );
39 }
40
41 DateCase.setTime( setTime );
42 var DateString = "var d = new Date("+startTime+"); d.setTime("+setTime+"); d" ;
43 var UTCDate = UTCDateFromTime ( Number(setTime) );
44 var LocalDate = LocalDateFromTime( Number(setTime) );
45
46 new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
47 new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
48
49 new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
50 new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
51 new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
52 new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
53 new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
54 new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes, DateCase.getUTCMinutes() );
55 new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds, DateCase.getUTCSeconds() );
56 new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
57
58 new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
59 new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
60 new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
61 new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
62 new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
63 new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
64 new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
65 new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
66
67 DateCase.toString = Object.prototype.toString;
68
69 new TestCase( SECTION,
70 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
71 "[object Date]",
72 DateCase.toString() );
73 }
74 function MyDate() {
75 this.year = 0;
76 this.month = 0;
77 this.date = 0;
78 this.hours = 0;
79 this.minutes = 0;
80 this.seconds = 0;
81 this.ms = 0;
82 }
83 function LocalDateFromTime(t) {
84 t = LocalTime(t);
85 return ( MyDateFromTime(t) );
86 }
87 function UTCDateFromTime(t) {
88 return ( MyDateFromTime(t) );
89 }
90 function MyDateFromTime( t ) {
91 var d = new MyDate();
92 d.year = YearFromTime(t);
93 d.month = MonthFromTime(t);
94 d.date = DateFromTime(t);
95 d.hours = HourFromTime(t);
96 d.minutes = MinFromTime(t);
97 d.seconds = SecFromTime(t);
98 d.ms = msFromTime(t);
99 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
100 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
101 d.day = WeekDay( d.value );
102 return (d);
103 }

mercurial