~ubuntu-branches/ubuntu/saucy/mozjs17/saucy

« back to all changes in this revision

Viewing changes to js/src/tests/ecma/Date/15.9.5.31-1.js

  • Committer: Package Import Robot
  • Author(s): Rico Tzschichholz
  • Date: 2013-05-25 12:24:23 UTC
  • Revision ID: package-import@ubuntu.com-20130525122423-zmxucrhtensw90xy
Tags: upstream-17.0.0
ImportĀ upstreamĀ versionĀ 17.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.31-1.js
 
9
 
 
10
   ECMA Section:      
 
11
   15.9.5.31 Date.prototype.setUTCHours(hour [, min [, sec [, ms ]]] )
 
12
 
 
13
   Description:
 
14
 
 
15
   If min is not specified, this behaves as if min were specified with
 
16
   the value getUTCMinutes( ).  If sec is not specified, this behaves
 
17
   as if sec were specified with the value getUTCSeconds ( ).  If ms
 
18
   is not specified, this behaves as if ms were specified with the
 
19
   value getUTCMilliseconds( ).
 
20
 
 
21
   1.Let t be this time value.
 
22
   2.Call ToNumber(hour).
 
23
   3.If min is not specified, compute MinFromTime(t);
 
24
   otherwise, call ToNumber(min).
 
25
   4.If sec is not specified, compute SecFromTime(t);
 
26
   otherwise, call ToNumber(sec).
 
27
   5.If ms is not specified, compute msFromTime(t);
 
28
   otherwise, call ToNumber(ms).
 
29
   6.Compute MakeTime(Result(2), Result(3), Result(4), Result(5)).
 
30
   7.Compute MakeDate(Day(t), Result(6)).
 
31
   8.Set the [[Value]] property of the this value to TimeClip(Result(7)).
 
32
 
 
33
   1.Return the value of the [[Value]] property of the this value.
 
34
   Author:             christine@netscape.com
 
35
   Date:               12 november 1997
 
36
*/
 
37
var SECTION = "15.9.5.31-1";
 
38
var VERSION = "ECMA_1";
 
39
startTest();
 
40
 
 
41
writeHeaderToLog(SECTION +
 
42
                 " Date.prototype.setUTCHours(hour [, min [, sec [, ms ]]] )");
 
43
 
 
44
addNewTestCase( 0, 0, void 0, void 0, void 0,
 
45
                "TDATE = new Date(0);(TDATE).setUTCHours(0);TDATE",
 
46
                UTCDateFromTime(SetUTCHours(0,0,0,0)),
 
47
                LocalDateFromTime(SetUTCHours(0,0,0,0)) );
 
48
 
 
49
addNewTestCase( 28800000, 23, 59, 999, void 0,
 
50
                "TDATE = new Date(28800000);(TDATE).setUTCHours(23,59,999);TDATE",
 
51
                UTCDateFromTime(SetUTCHours(28800000,23,59,999)),
 
52
                LocalDateFromTime(SetUTCHours(28800000,23,59,999)) );
 
53
 
 
54
addNewTestCase( 28800000,999,999, void 0, void 0,
 
55
                "TDATE = new Date(28800000);(TDATE).setUTCHours(999,999);TDATE",
 
56
                UTCDateFromTime(SetUTCHours(28800000,999,999)),
 
57
                LocalDateFromTime(SetUTCHours(28800000,999,999)) );
 
58
 
 
59
addNewTestCase( 28800000, 999, void 0, void 0, void 0,
 
60
                "TDATE = new Date(28800000);(TDATE).setUTCHours(999);TDATE",
 
61
                UTCDateFromTime(SetUTCHours(28800000,999,0)),
 
62
                LocalDateFromTime(SetUTCHours(28800000,999,0)) );
 
63
 
 
64
addNewTestCase( 28800000, -8670, void 0, void 0, void 0,
 
65
                "TDATE = new Date(28800000);(TDATE).setUTCHours(-8670);TDATE",
 
66
                UTCDateFromTime(SetUTCHours(28800000,-8670)),
 
67
                LocalDateFromTime(SetUTCHours(28800000,-8670)) );
 
68
 
 
69
// modify hours to remove dst ambiguity
 
70
addNewTestCase( 946684800000, 1235567, void 0, void 0, void 0,
 
71
                "TDATE = new Date(946684800000);(TDATE).setUTCHours(1235567);TDATE",
 
72
                UTCDateFromTime(SetUTCHours(946684800000,1235567)),
 
73
                LocalDateFromTime(SetUTCHours(946684800000,1235567)) );
 
74
 
 
75
addNewTestCase( -2208988800000, 59, 999, void 0, void 0,
 
76
                "TDATE = new Date(-2208988800000);(TDATE).setUTCHours(59,999);TDATE",
 
77
                UTCDateFromTime(SetUTCHours(-2208988800000,59,999)),
 
78
                LocalDateFromTime(SetUTCHours(-2208988800000,59,999)) );
 
79
 
 
80
test();
 
81
 
 
82
function addNewTestCase( time, hours, min, sec, ms, DateString, UTCDate, LocalDate) {
 
83
 
 
84
  DateCase = new Date(time);
 
85
  if ( min == void 0 ) {
 
86
    DateCase.setUTCHours( hours );
 
87
  } else {
 
88
    if ( sec == void 0 ) {
 
89
      DateCase.setUTCHours( hours, min );
 
90
    } else {
 
91
      if ( ms == void 0 ) {
 
92
        DateCase.setUTCHours( hours, min, sec );
 
93
      } else {
 
94
        DateCase.setUTCHours( hours, min, sec, ms );
 
95
      }
 
96
    }
 
97
  }
 
98
 
 
99
  new TestCase( SECTION, DateString+".getTime()",            UTCDate.value,
 
100
                DateCase.getTime() );
 
101
  new TestCase( SECTION, DateString+".valueOf()",            UTCDate.value,
 
102
                DateCase.valueOf() );
 
103
  new TestCase( SECTION, DateString+".getUTCFullYear()",     UTCDate.year,
 
104
                DateCase.getUTCFullYear() );
 
105
  new TestCase( SECTION, DateString+".getUTCMonth()",        UTCDate.month,
 
106
                DateCase.getUTCMonth() );
 
107
  new TestCase( SECTION, DateString+".getUTCDate()",         UTCDate.date,
 
108
                DateCase.getUTCDate() );
 
109
  new TestCase( SECTION, DateString+".getUTCDay()",          UTCDate.day,
 
110
                DateCase.getUTCDay() );
 
111
  new TestCase( SECTION, DateString+".getUTCHours()",        UTCDate.hours,
 
112
                DateCase.getUTCHours() );
 
113
  new TestCase( SECTION, DateString+".getUTCMinutes()",      UTCDate.minutes,
 
114
                DateCase.getUTCMinutes() );
 
115
  new TestCase( SECTION, DateString+".getUTCSeconds()",      UTCDate.seconds,
 
116
                DateCase.getUTCSeconds() );
 
117
  new TestCase( SECTION, DateString+".getUTCMilliseconds()", UTCDate.ms,
 
118
                DateCase.getUTCMilliseconds() );
 
119
 
 
120
  new TestCase( SECTION, DateString+".getFullYear()",        LocalDate.year,
 
121
                DateCase.getFullYear() );
 
122
  new TestCase( SECTION, DateString+".getMonth()",           LocalDate.month,
 
123
                DateCase.getMonth() );
 
124
  new TestCase( SECTION, DateString+".getDate()",            LocalDate.date,
 
125
                DateCase.getDate() );
 
126
  new TestCase( SECTION, DateString+".getDay()",             LocalDate.day,
 
127
                DateCase.getDay() );
 
128
  new TestCase( SECTION, DateString+".getHours()",           LocalDate.hours,
 
129
                DateCase.getHours() );
 
130
  new TestCase( SECTION, DateString+".getMinutes()",         LocalDate.minutes,
 
131
                DateCase.getMinutes() );
 
132
  new TestCase( SECTION, DateString+".getSeconds()",         LocalDate.seconds,
 
133
                DateCase.getSeconds() );
 
134
  new TestCase( SECTION, DateString+".getMilliseconds()",    LocalDate.ms,
 
135
                DateCase.getMilliseconds() );
 
136
 
 
137
  DateCase.toString = Object.prototype.toString;
 
138
 
 
139
  new TestCase( SECTION,
 
140
                DateString+".toString=Object.prototype.toString;" +
 
141
                DateString+".toString()",
 
142
                "[object Date]",
 
143
                DateCase.toString() );
 
144
}
 
145
function MyDate() {
 
146
  this.year = 0;
 
147
  this.month = 0;
 
148
  this.date = 0;
 
149
  this.hours = 0;
 
150
  this.minutes = 0;
 
151
  this.seconds = 0;
 
152
  this.ms = 0;
 
153
}
 
154
function LocalDateFromTime(t) {
 
155
  t = LocalTime(t);
 
156
  return ( MyDateFromTime(t) );
 
157
}
 
158
function UTCDateFromTime(t) {
 
159
  return ( MyDateFromTime(t) );
 
160
}
 
161
function MyDateFromTime( t ) {
 
162
  var d = new MyDate();
 
163
  d.year = YearFromTime(t);
 
164
  d.month = MonthFromTime(t);
 
165
  d.date = DateFromTime(t);
 
166
  d.hours = HourFromTime(t);
 
167
  d.minutes = MinFromTime(t);
 
168
  d.seconds = SecFromTime(t);
 
169
  d.ms = msFromTime(t);
 
170
 
 
171
  d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
 
172
  d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
 
173
  d.day = WeekDay( d.value );
 
174
 
 
175
  return (d);
 
176
}
 
177
function SetUTCHours( t, hour, min, sec, ms ) {
 
178
  var TIME = t;
 
179
  var HOUR = Number(hour);
 
180
  var MIN =  ( min == void 0) ? MinFromTime(TIME) : Number(min);
 
181
  var SEC  = ( sec == void 0) ? SecFromTime(TIME) : Number(sec);
 
182
  var MS   = ( ms == void 0 ) ? msFromTime(TIME)  : Number(ms);
 
183
  var RESULT6 = MakeTime( HOUR,
 
184
                          MIN,
 
185
                          SEC,
 
186
                          MS );
 
187
  return ( TimeClip(MakeDate(Day(TIME), RESULT6)) );
 
188
}