js/src/tests/ecma/Date/15.9.5.37-5.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:84edde6c71ba
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.37-1.js
9 ECMA Section: 15.9.5.37 Date.prototype.setUTCFullYear(year [, mon [, date ]] )
10 Description:
11
12 If mon is not specified, this behaves as if mon were specified with the
13 value getUTCMonth( ). If date is not specified, this behaves as if date
14 were specified with the value getUTCDate( ).
15
16 1. Let t be this time value; but if this time value is NaN, let t be +0.
17 2. Call ToNumber(year).
18 3. If mon is not specified, compute MonthFromTime(t); otherwise, call
19 ToNumber(mon).
20 4. If date is not specified, compute DateFromTime(t); otherwise, call
21 ToNumber(date).
22 5. Compute MakeDay(Result(2), Result(3), Result(4)).
23 6. Compute MakeDate(Result(5), TimeWithinDay(t)).
24 7. Set the [[Value]] property of the this value to TimeClip(Result(6)).
25 8. Return the value of the [[Value]] property of the this value.
26
27 Author: christine@netscape.com
28 Date: 12 november 1997
29
30 Added some Year 2000 test cases.
31 */
32 var SECTION = "15.9.5.37-1";
33 var VERSION = "ECMA_1";
34 startTest();
35
36 writeHeaderToLog( SECTION + " Date.prototype.setUTCFullYear(year [, mon [, date ]] )");
37
38 // Dates around 1900
39 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1900);TDATE",
40 UTCDateFromTime(SetUTCFullYear(0,1900)),
41 LocalDateFromTime(SetUTCFullYear(0,1900)) );
42
43 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1899);TDATE",
44 UTCDateFromTime(SetUTCFullYear(0,1899)),
45 LocalDateFromTime(SetUTCFullYear(0,1899)) );
46
47 addNewTestCase( "TDATE = new Date(0); TDATE.setUTCFullYear(1901);TDATE",
48 UTCDateFromTime(SetUTCFullYear(0,1901)),
49 LocalDateFromTime(SetUTCFullYear(0,1901)) );
50
51 test();
52
53 function addNewTestCase( DateString, UTCDate, LocalDate) {
54 DateCase = eval( DateString );
55
56 new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
57 new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
58
59 new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
60 new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
61 new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
62 new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
63 new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
64 new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
65 new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
66 new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
67
68 new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
69 new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
70 new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
71 new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
72 new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
73 new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
74 new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
75 new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
76
77 DateCase.toString = Object.prototype.toString;
78
79 new TestCase( SECTION,
80 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
81 "[object Date]",
82 DateCase.toString() );
83 }
84
85 function MyDate() {
86 this.year = 0;
87 this.month = 0;
88 this.date = 0;
89 this.hours = 0;
90 this.minutes = 0;
91 this.seconds = 0;
92 this.ms = 0;
93 }
94 function LocalDateFromTime(t) {
95 t = LocalTime(t);
96 return ( MyDateFromTime(t) );
97 }
98 function UTCDateFromTime(t) {
99 return ( MyDateFromTime(t) );
100 }
101 function MyDateFromTime( t ) {
102 var d = new MyDate();
103 d.year = YearFromTime(t);
104 d.month = MonthFromTime(t);
105 d.date = DateFromTime(t);
106 d.hours = HourFromTime(t);
107 d.minutes = MinFromTime(t);
108 d.seconds = SecFromTime(t);
109 d.ms = msFromTime(t);
110
111 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
112 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
113 d.day = WeekDay( d.value );
114
115 return (d);
116 }
117 function SetUTCFullYear( t, year, mon, date ) {
118 var T = ( t != t ) ? 0 : t;
119 var YEAR = Number(year);
120 var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon );
121 var DATE = ( date == void 0 ) ? DateFromTime(T) : Number( date );
122 var DAY = MakeDay( YEAR, MONTH, DATE );
123
124 return ( TimeClip(MakeDate(DAY, TimeWithinDay(T))) );
125 }

mercurial