Debian Codegraph @

rhino/testsrc/tests/ecma/Date/15.9.5.37-3.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.37-3.js';
7
8 /**
9 File Name: 15.9.5.37-1.js
10 ECMA Section: 15.9.5.37 Date.prototype.setUTCFullYear(year [, mon [, date ]] )
11 Description:
12
13 If mon is not specified, this behaves as if mon were specified with the
14 value getUTCMonth( ). If date is not specified, this behaves as if date
15 were specified with the value getUTCDate( ).
16
17 1. Let t be this time value; but if this time 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 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: [email protected]
29 Date: 12 november 1997
30
31 Added some Year 2000 test cases.
32 */
33 var SECTION = "15.9.5.37-1";
34 var VERSION = "ECMA_1";
35 startTest();
36
37 writeHeaderToLog( SECTION + " Date.prototype.setUTCFullYear(year [, mon [, date ]] )");
38
39
40 // Dates around 29 February 2000
41
42 var UTC_FEB_29_1972 = TIME_1970 + TimeInYear(1970) + TimeInYear(1971) +
43 31*msPerDay + 28*msPerDay;
44
45 var PST_FEB_29_1972 = UTC_FEB_29_1972 - TZ_DIFF * msPerHour;
46
47 addNewTestCase( "TDATE = new Date("+UTC_FEB_29_1972+"); "+
48 "TDATE.setUTCFullYear(2000);TDATE",
49 UTCDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)),
50 LocalDateFromTime(SetUTCFullYear(UTC_FEB_29_1972,2000)) );
51
52 addNewTestCase( "TDATE = new Date("+PST_FEB_29_1972+"); "+
53 "TDATE.setUTCFullYear(2000);TDATE",
54 UTCDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)),
55 LocalDateFromTime(SetUTCFullYear(PST_FEB_29_1972,2000)) );
56
57 test();
58
59 function addNewTestCase( DateString, UTCDate, LocalDate) {
60 DateCase = eval( DateString );
61
62 new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
63 new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
64
65 new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
66 new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
67 new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
68 new TestCase( SECTION, DateString+".getUTCDay()", UTCDate.day, DateCase.getUTCDay() );
69 new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
70 new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
71 new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
72 new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
73
74 new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
75 new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
76 new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
77 new TestCase( SECTION, DateString+".getDay()", LocalDate.day, DateCase.getDay() );
78 new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
79 new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
80 new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
81 new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
82
83 DateCase.toString = Object.prototype.toString;
84
85 new TestCase( SECTION,
86 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
87 "[object Date]",
88 DateCase.toString() );
89 }
90
91 function MyDate() {
92 this.year = 0;
93 this.month = 0;
94 this.date = 0;
95 this.hours = 0;
96 this.minutes = 0;
97 this.seconds = 0;
98 this.ms = 0;
99 }
100 function LocalDateFromTime(t) {
101 t = LocalTime(t);
102 return ( MyDateFromTime(t) );
103 }
104 function UTCDateFromTime(t) {
105 return ( MyDateFromTime(t) );
106 }
107 function MyDateFromTime( t ) {
108 var d = new MyDate();
109 d.year = YearFromTime(t);
110 d.month = MonthFromTime(t);
111 d.date = DateFromTime(t);
112 d.hours = HourFromTime(t);
113 d.minutes = MinFromTime(t);
114 d.seconds = SecFromTime(t);
115 d.ms = msFromTime(t);
116
117 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
118 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
119 d.day = WeekDay( d.value );
120
121 return (d);
122 }
123 function SetUTCFullYear( t, year, mon, date ) {
124 var T = ( t != t ) ? 0 : t;
125 var YEAR = Number(year);
126 var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon );
127 var DATE = ( date == void 0 ) ? DateFromTime(T) : Number( date );
128 var DAY = MakeDay( YEAR, MONTH, DATE );
129
130 return ( TimeClip(MakeDate(DAY, TimeWithinDay(T))) );
131 }