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.32-1.js
24    ECMA Section:       15.9.5.32 Date.prototype.setDate(date)
25    Description:
26    1.  Let t be the result of LocalTime(this time value).
27    2.  Call ToNumber(date).
28    3.  Compute MakeDay(YearFromTime(t), MonthFromTime(t), Result(2)).
29    4.  Compute UTC(MakeDate(Result(3), TimeWithinDay(t))).
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
33    Author:             christine@netscape.com
34    Date:               12 november 1997
35*/
36    var SECTION = "15.9.5.32-1";
37    var VERSION = "ECMA_1";
38    startTest();
39
40    writeHeaderToLog( SECTION + " Date.prototype.setDate(date) ");
41
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, 1,
61                    "TDATE = new Date(0);(TDATE).setDate(1);TDATE" );
62
63/*
64    addNewTestCase( "TDATE = new Date(86400000);(TDATE).setDate(1);TDATE",
65                    UTCDateFromTime(SetDate(86400000,1)),
66                    LocalDateFromTime(SetDate(86400000,1)) );
67
68    addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1972);TDATE",
69                    UTCDateFromTime(SetUTCFullYear(0,1972)),
70                    LocalDateFromTime(SetUTCFullYear(0,1972)) );
71
72    addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1968);TDATE",
73                    UTCDateFromTime(SetUTCFullYear(0,1968)),
74                    LocalDateFromTime(SetUTCFullYear(0,1968)) );
75
76    addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1969);TDATE",
77                    UTCDateFromTime(SetUTCFullYear(0,1969)),
78                    LocalDateFromTime(SetUTCFullYear(0,1969)) );
79*/
80}
81function addNewTestCase( t, d, DateString ) {
82    var DateCase = new Date( t );
83    DateCase.setDate( d );
84
85    var UTCDate = UTCDateFromTime(SetDate(t, d));
86    var LocalDate=LocalDateFromTime(SetDate(t,d));
87
88    var item = testcases.length;
89
90    testcases[item++] = new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
91    testcases[item++] = new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
92
93    testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
94    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
95    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
96    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
97    testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
98    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
99    testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
100    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
101
102    testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
103    testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
104    testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
105    testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
106    testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
107    testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
108    testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
109    testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
110
111    DateCase.toString = Object.prototype.toString;
112
113    testcases[item++] = new TestCase( SECTION,
114                                      DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
115                                      "[object Date]",
116                                      DateCase.toString() );
117}
118function MyDate() {
119    this.year = 0;
120    this.month = 0;
121    this.date = 0;
122    this.hours = 0;
123    this.minutes = 0;
124    this.seconds = 0;
125    this.ms = 0;
126}
127function LocalDateFromTime(t) {
128    t = LocalTime(t);
129    return ( MyDateFromTime(t) );
130}
131function UTCDateFromTime(t) {
132 return ( MyDateFromTime(t) );
133}
134function MyDateFromTime( t ) {
135    var d = new MyDate();
136    d.year = YearFromTime(t);
137    d.month = MonthFromTime(t);
138    d.date = DateFromTime(t);
139    d.hours = HourFromTime(t);
140    d.minutes = MinFromTime(t);
141    d.seconds = SecFromTime(t);
142    d.ms = msFromTime(t);
143
144    d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
145    d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
146    d.day = WeekDay( d.value );
147
148    return (d);
149}
150
151function SetDate( t, date ) {
152    var T       = LocalTime( t );
153    var DATE    = Number( date );
154    var RESULT3 = MakeDay(YearFromTime(T), MonthFromTime(T), DATE );
155    var UTC_DATE = UTC( MakeDate(RESULT3, TimeWithinDay(T)) );
156    return ( TimeClip(UTC_DATE) );
157}
158