Debian Codegraph @

rhino/testsrc/tests/ecma/Date/15.9.5.32-1.js

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