~ubuntu-branches/ubuntu/trusty/mozjs17/trusty

« back to all changes in this revision

Viewing changes to js/src/tests/ecma/Date/15.9.5.24-6.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.24-1.js
 
9
   ECMA Section:       15.9.5.24 Date.prototype.setTime(time)
 
10
   Description:
 
11
   1.      If the this value is not a Date object, generate a runtime error.
 
12
   2.      Call ToNumber(time).
 
13
   3.      Call TimeClip(Result(1)).
 
14
   4.      Set the [[Value]] property of the this value to Result(2).
 
15
   5.      Return the value of the [[Value]] property of the this value.
 
16
   Author:             christine@netscape.com
 
17
   Date:               12 november 1997
 
18
 
 
19
*/
 
20
var TITLE = "Date.prototype.setTime"
 
21
  var SECTION = "15.9.5.24-1";
 
22
var VERSION = "ECMA_1";
 
23
startTest();
 
24
 
 
25
writeHeaderToLog( SECTION + " Date.prototype.setMilliseconds(ms)");
 
26
 
 
27
 
 
28
addTestCase( 0, "-2208988800000" );
 
29
 
 
30
test();
 
31
 
 
32
function addTestCase( startms, newms ) {
 
33
 
 
34
  var DateCase = new Date( startms );
 
35
  DateCase.setMilliseconds( newms );
 
36
  var DateString = "var date = new Date("+ startms +"); date.setMilliseconds("+ newms +"); date";
 
37
  var UTCDate = UTCDateFromTime( Number(newms) );
 
38
  var LocalDate = LocalDateFromTime( Number(newms) );
 
39
 
 
40
  new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
 
41
  new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
 
42
 
 
43
  new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
 
44
  new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
 
45
  new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
 
46
 
 
47
  new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
 
48
  new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
 
49
  new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
 
50
  new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
 
51
 
 
52
  new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
 
53
  new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
 
54
  new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
 
55
 
 
56
  new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
 
57
  new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
 
58
  new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
 
59
  new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
 
60
 
 
61
  DateCase.toString = Object.prototype.toString;
 
62
 
 
63
  new TestCase( SECTION,
 
64
                DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
 
65
                "[object Date]",
 
66
                DateCase.toString() );
 
67
}
 
68
 
 
69
function MyDate() {
 
70
  this.year = 0;
 
71
  this.month = 0;
 
72
  this.date = 0;
 
73
  this.hours = 0;
 
74
  this.minutes = 0;
 
75
  this.seconds = 0;
 
76
  this.ms = 0;
 
77
}
 
78
function LocalDateFromTime(t) {
 
79
  t = LocalTime(t);
 
80
  return ( MyDateFromTime(t) );
 
81
}
 
82
function UTCDateFromTime(t) {
 
83
  return ( MyDateFromTime(t) );
 
84
}
 
85
function MyDateFromTime( t ) {
 
86
  var d = new MyDate();
 
87
  d.year = YearFromTime(t);
 
88
  d.month = MonthFromTime(t);
 
89
  d.date = DateFromTime(t);
 
90
  d.hours = HourFromTime(t);
 
91
  d.minutes = MinFromTime(t);
 
92
  d.seconds = SecFromTime(t);
 
93
  d.ms = msFromTime(t);
 
94
 
 
95
  d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
 
96
  d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
 
97
  d.day = WeekDay( d.value );
 
98
 
 
99
  return (d);
 
100
}