js/src/tests/ecma/Date/15.9.5.32-1.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:a1abcf757d6d
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.32-1.js
9 ECMA Section: 15.9.5.32 Date.prototype.setDate(date)
10 Description:
11 1. Let t be the result of LocalTime(this time value).
12 2. Call ToNumber(date).
13 3. Compute MakeDay(YearFromTime(t), MonthFromTime(t), Result(2)).
14 4. Compute UTC(MakeDate(Result(3), TimeWithinDay(t))).
15 5. Set the [[Value]] property of the this value to TimeClip(Result(4)).
16 6. Return the value of the [[Value]] property of the this value.
17
18 Author: christine@netscape.com
19 Date: 12 november 1997
20 */
21 var SECTION = "15.9.5.32-1";
22 var VERSION = "ECMA_1";
23 startTest();
24
25 writeHeaderToLog( SECTION + " Date.prototype.setDate(date) ");
26
27 addNewTestCase( 0, 1,
28 "TDATE = new Date(0);(TDATE).setDate(1);TDATE" );
29
30 test();
31
32 function addNewTestCase( t, d, DateString ) {
33 var DateCase = new Date( t );
34 DateCase.setDate( d );
35
36 var UTCDate = UTCDateFromTime(SetDate(t, d));
37 var LocalDate=LocalDateFromTime(SetDate(t,d));
38
39
40 new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
41 new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
42
43 new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
44 new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
45 new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
46 new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
47 new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
48 new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
49 new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
50 new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
51
52 new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
53 new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
54 new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
55 new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
56 new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
57 new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
58 new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
59 new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
60
61 DateCase.toString = Object.prototype.toString;
62
63 new TestCase( SECTION,
64 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
65 "[object Date]",
66 DateCase.toString() );
67 }
68 function MyDate() {
69 this.year = 0;
70 this.month = 0;
71 this.date = 0;
72 this.hours = 0;
73 this.minutes = 0;
74 this.seconds = 0;
75 this.ms = 0;
76 }
77 function LocalDateFromTime(t) {
78 t = LocalTime(t);
79 return ( MyDateFromTime(t) );
80 }
81 function UTCDateFromTime(t) {
82 return ( MyDateFromTime(t) );
83 }
84 function MyDateFromTime( t ) {
85 var d = new MyDate();
86 d.year = YearFromTime(t);
87 d.month = MonthFromTime(t);
88 d.date = DateFromTime(t);
89 d.hours = HourFromTime(t);
90 d.minutes = MinFromTime(t);
91 d.seconds = SecFromTime(t);
92 d.ms = msFromTime(t);
93
94 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
95 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
96 d.day = WeekDay( d.value );
97
98 return (d);
99 }
100
101 function SetDate( t, date ) {
102 var T = LocalTime( t );
103 var DATE = Number( date );
104 var RESULT3 = MakeDay(YearFromTime(T), MonthFromTime(T), DATE );
105 var UTC_DATE = UTC( MakeDate(RESULT3, TimeWithinDay(T)) );
106 return ( TimeClip(UTC_DATE) );
107 }

mercurial