• 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.33-1.js
24    ECMA Section:       15.9.5.33 Date.prototype.setUTCDate(date)
25    Description:
26    1.  Let t be this time value.
27    2.  Call ToNumber(date).
28    3.  Compute MakeDay(YearFromTime(t), MonthFromTime(t), Result(2)).
29    4.  Compute 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.33-1";
37    var VERSION = "ECMA_1";
38    startTest();
39
40    writeHeaderToLog( SECTION + " Date.prototype.setUTCDate(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( "TDATE = new Date(0);(TDATE).setUTCDate(31);TDATE",
61                    UTCDateFromTime(SetUTCDate(0,31)),
62                    LocalDateFromTime(SetUTCDate(0,31)) );
63
64    addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCDate(1);TDATE",
65                    UTCDateFromTime(SetUTCDate(0,1)),
66                    LocalDateFromTime(SetUTCDate(0,1)) );
67
68    addNewTestCase( "TDATE = new Date(86400000);(TDATE).setUTCDate(1);TDATE",
69                    UTCDateFromTime(SetUTCDate(86400000,1)),
70                    LocalDateFromTime(SetUTCDate(86400000,1)) );
71/*
72    addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1972);TDATE",
73                    UTCDateFromTime(SetUTCFullYear(0,1972)),
74                    LocalDateFromTime(SetUTCFullYear(0,1972)) );
75
76    addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1968);TDATE",
77                    UTCDateFromTime(SetUTCFullYear(0,1968)),
78                    LocalDateFromTime(SetUTCFullYear(0,1968)) );
79
80    addNewTestCase( "TDATE = new Date(0);(TDATE).setUTCFullYear(1969);TDATE",
81                    UTCDateFromTime(SetUTCFullYear(0,1969)),
82                    LocalDateFromTime(SetUTCFullYear(0,1969)) );
83*/
84}
85function addNewTestCase( DateString, UTCDate, LocalDate) {
86    DateCase = eval( DateString );
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}
150function SetUTCDate( t, date ) {
151    var T       = t;
152    var DATE    = Number( date );
153    var RESULT3 = MakeDay(YearFromTime(T), MonthFromTime(T), DATE );
154    return ( TimeClip(MakeDate(RESULT3, TimeWithinDay(t))) );
155}
156
157