js/src/tests/ecma/Date/15.9.5.36-2.js

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

mercurial