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

« back to all changes in this revision

Viewing changes to js/src/tests/ecma/Date/15.9.5.36-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.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-1";
 
35
var VERSION = "ECMA_1";
 
36
startTest();
 
37
 
 
38
writeHeaderToLog( SECTION + " Date.prototype.setFullYear(year [, mon [, date ]] )");
 
39
 
 
40
// feb 29, 2000
 
41
addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000);TDATE",
 
42
                UTCDateFromTime(SetFullYear(0,2000)),
 
43
                LocalDateFromTime(SetFullYear(0,2000)) );
 
44
 
 
45
addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,1);TDATE",
 
46
                UTCDateFromTime(SetFullYear(0,2000,1)),
 
47
                LocalDateFromTime(SetFullYear(0,2000,1)) );
 
48
 
 
49
addNewTestCase( "TDATE = new Date(0);(TDATE).setFullYear(2000,1,29);TDATE",
 
50
                UTCDateFromTime(SetFullYear(0,2000,1,29)),
 
51
                LocalDateFromTime(SetFullYear(0,2000,1,29)) );
 
52
 
 
53
test();
 
54
 
 
55
function addNewTestCase( DateString, UTCDate, LocalDate) {
 
56
  DateCase = eval( DateString );
 
57
 
 
58
  new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
 
59
  new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
 
60
 
 
61
  new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
 
62
  new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
 
63
  new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
 
64
  new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
 
65
  new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
 
66
  new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
 
67
  new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
 
68
  new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
 
69
 
 
70
  new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
 
71
  new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
 
72
  new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
 
73
  new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
 
74
  new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
 
75
  new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
 
76
  new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
 
77
  new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
 
78
 
 
79
  DateCase.toString = Object.prototype.toString;
 
80
 
 
81
  new TestCase( SECTION,
 
82
                DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
 
83
                "[object Date]",
 
84
                DateCase.toString() );
 
85
}
 
86
 
 
87
function MyDate() {
 
88
  this.year = 0;
 
89
  this.month = 0;
 
90
  this.date = 0;
 
91
  this.hours = 0;
 
92
  this.minutes = 0;
 
93
  this.seconds = 0;
 
94
  this.ms = 0;
 
95
}
 
96
function LocalDateFromTime(t) {
 
97
  t = LocalTime(t);
 
98
  return ( MyDateFromTime(t) );
 
99
}
 
100
function UTCDateFromTime(t) {
 
101
  return ( MyDateFromTime(t) );
 
102
}
 
103
function MyDateFromTime( t ) {
 
104
  var d = new MyDate();
 
105
  d.year = YearFromTime(t);
 
106
  d.month = MonthFromTime(t);
 
107
  d.date = DateFromTime(t);
 
108
  d.hours = HourFromTime(t);
 
109
  d.minutes = MinFromTime(t);
 
110
  d.seconds = SecFromTime(t);
 
111
  d.ms = msFromTime(t);
 
112
 
 
113
  d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
 
114
  d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
 
115
  d.day = WeekDay( d.value );
 
116
 
 
117
  return (d);
 
118
}
 
119
function SetFullYear( t, year, mon, date ) {
 
120
  var T = ( isNaN(t) ) ? 0 : LocalTime(t) ;
 
121
  var YEAR = Number( year );
 
122
  var MONTH = ( mon == void 0 ) ? MonthFromTime(T) : Number( mon );
 
123
  var DATE = ( date == void 0 ) ? DateFromTime(T)  : Number( date );
 
124
 
 
125
  var DAY = MakeDay( YEAR, MONTH, DATE );
 
126
  var UTC_DATE = UTC(MakeDate( DAY, TimeWithinDay(T)));
 
127
 
 
128
  return ( TimeClip(UTC_DATE) );
 
129
}