Debian Codegraph @

rhino/testsrc/tests/ecma/Date/15.9.5.27-1.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.27-1.js';
7
8 /**
9 File Name: 15.9.5.27-1.js
10 ECMA Section: 15.9.5.27 Date.prototype.setUTCSeconds(sec [,ms])
11 Description:
12
13 If ms is not specified, this behaves as if ms were specified with the
14 value getUTCMilliseconds( ).
15
16 1. Let t be this time value.
17 2. Call ToNumber(sec).
18 3. If ms is not specified, compute msFromTime(t); otherwise, call
19 ToNumber(ms)
20 4. Compute MakeTime(HourFromTime(t), MinFromTime(t), Result(2), Result(3))
21 5. Compute MakeDate(Day(t), Result(4)).
22 6. Set the [[Value]] property of the this value to TimeClip(Result(5)).
23 7. Return the value of the [[Value]] property of the this value.
24
25 Author: [email protected]
26 Date: 12 november 1997
27 */
28 var SECTION = "15.9.5.27-1";
29 var VERSION = "ECMA_1";
30 startTest();
31
32 writeHeaderToLog( SECTION + " Date.prototype.setUTCSeconds(sec [,ms] )");
33
34 addNewTestCase( 0, 0, 0, "TDATE = new Date(0);(TDATE).setUTCSeconds(0,0);TDATE",
35 UTCDateFromTime(SetUTCSeconds(0,0,0)),
36 LocalDateFromTime(SetUTCSeconds(0,0,0)) );
37
38 addNewTestCase( 28800000,59,999,
39 "TDATE = new Date(28800000);(TDATE).setUTCSeconds(59,999);TDATE",
40 UTCDateFromTime(SetUTCSeconds(28800000,59,999)),
41 LocalDateFromTime(SetUTCSeconds(28800000,59,999)) );
42
43 addNewTestCase( 28800000,999,999,
44 "TDATE = new Date(28800000);(TDATE).setUTCSeconds(999,999);TDATE",
45 UTCDateFromTime(SetUTCSeconds(28800000,999,999)),
46 LocalDateFromTime(SetUTCSeconds(28800000,999,999)) );
47
48 addNewTestCase( 28800000, 999, void 0,
49 "TDATE = new Date(28800000);(TDATE).setUTCSeconds(999);TDATE",
50 UTCDateFromTime(SetUTCSeconds(28800000,999,0)),
51 LocalDateFromTime(SetUTCSeconds(28800000,999,0)) );
52
53 addNewTestCase( 28800000, -28800, void 0,
54 "TDATE = new Date(28800000);(TDATE).setUTCSeconds(-28800);TDATE",
55 UTCDateFromTime(SetUTCSeconds(28800000,-28800)),
56 LocalDateFromTime(SetUTCSeconds(28800000,-28800)) );
57
58 addNewTestCase( 946684800000, 1234567, void 0,
59 "TDATE = new Date(946684800000);(TDATE).setUTCSeconds(1234567);TDATE",
60 UTCDateFromTime(SetUTCSeconds(946684800000,1234567)),
61 LocalDateFromTime(SetUTCSeconds(946684800000,1234567)) );
62
63 addNewTestCase( -2208988800000,59,999,
64 "TDATE = new Date(-2208988800000);(TDATE).setUTCSeconds(59,999);TDATE",
65 UTCDateFromTime(SetUTCSeconds(-2208988800000,59,999)),
66 LocalDateFromTime(SetUTCSeconds(-2208988800000,59,999)) );
67
68 test();
69
70 function addNewTestCase( startTime, sec, ms, DateString, UTCDate, LocalDate) {
71 DateCase = new Date( startTime );
72 if ( ms == void 0) {
73 DateCase.setSeconds( sec );
74 } else {
75 DateCase.setSeconds( sec, ms );
76 }
77
78 new TestCase( SECTION, DateString+".getTime()", UTCDate.value, DateCase.getTime() );
79 new TestCase( SECTION, DateString+".valueOf()", UTCDate.value, DateCase.valueOf() );
80
81 new TestCase( SECTION, DateString+".getUTCFullYear()", UTCDate.year, DateCase.getUTCFullYear() );
82 new TestCase( SECTION, DateString+".getUTCMonth()", UTCDate.month, DateCase.getUTCMonth() );
83 new TestCase( SECTION, DateString+".getUTCDate()", UTCDate.date, DateCase.getUTCDate() );
84
85 new TestCase( SECTION, DateString+".getUTCHours()", UTCDate.hours, DateCase.getUTCHours() );
86 new TestCase( SECTION, DateString+".getUTCMinutes()", UTCDate.minutes,DateCase.getUTCMinutes() );
87 new TestCase( SECTION, DateString+".getUTCSeconds()", UTCDate.seconds,DateCase.getUTCSeconds() );
88 new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms, DateCase.getUTCMilliseconds() );
89
90 new TestCase( SECTION, DateString+".getFullYear()", LocalDate.year, DateCase.getFullYear() );
91 new TestCase( SECTION, DateString+".getMonth()", LocalDate.month, DateCase.getMonth() );
92 new TestCase( SECTION, DateString+".getDate()", LocalDate.date, DateCase.getDate() );
93
94 new TestCase( SECTION, DateString+".getHours()", LocalDate.hours, DateCase.getHours() );
95 new TestCase( SECTION, DateString+".getMinutes()", LocalDate.minutes, DateCase.getMinutes() );
96 new TestCase( SECTION, DateString+".getSeconds()", LocalDate.seconds, DateCase.getSeconds() );
97 new TestCase( SECTION, DateString+".getMilliseconds()", LocalDate.ms, DateCase.getMilliseconds() );
98
99 DateCase.toString = Object.prototype.toString;
100
101 new TestCase( SECTION,
102 DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
103 "[object Date]",
104 DateCase.toString() );
105 }
106
107 function MyDate() {
108 this.year = 0;
109 this.month = 0;
110 this.date = 0;
111 this.hours = 0;
112 this.minutes = 0;
113 this.seconds = 0;
114 this.ms = 0;
115 }
116 function LocalDateFromTime(t) {
117 t = LocalTime(t);
118 return ( MyDateFromTime(t) );
119 }
120 function UTCDateFromTime(t) {
121 return ( MyDateFromTime(t) );
122 }
123 function MyDateFromTime( t ) {
124 var d = new MyDate();
125 d.year = YearFromTime(t);
126 d.month = MonthFromTime(t);
127 d.date = DateFromTime(t);
128 d.hours = HourFromTime(t);
129 d.minutes = MinFromTime(t);
130 d.seconds = SecFromTime(t);
131 d.ms = msFromTime(t);
132
133 d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
134 d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
135 d.day = WeekDay( d.value );
136
137 return (d);
138 }
139
140 function SetUTCSeconds( t, s, m ) {
141 var TIME = t;
142 var SEC = Number(s);
143 var MS = ( m == void 0 ) ? msFromTime(TIME) : Number( m );
144 var RESULT4 = MakeTime( HourFromTime( TIME ),
145 MinFromTime( TIME ),
146 SEC,
147 MS );
148 return ( TimeClip(MakeDate(Day(TIME), RESULT4)) );
149 }
150