diff options
Diffstat (limited to 'js/src/tests/ecma_3/Date')
-rw-r--r-- | js/src/tests/ecma_3/Date/15.9.1.2-01.js | 29 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/15.9.4.3.js | 200 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/15.9.5.3.js | 118 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/15.9.5.4.js | 151 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/15.9.5.5-02.js | 66 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/15.9.5.5.js | 111 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/15.9.5.6.js | 119 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/15.9.5.7.js | 108 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/browser.js | 0 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/regress-452786.js | 33 | ||||
-rw-r--r-- | js/src/tests/ecma_3/Date/shell.js | 530 |
11 files changed, 1465 insertions, 0 deletions
diff --git a/js/src/tests/ecma_3/Date/15.9.1.2-01.js b/js/src/tests/ecma_3/Date/15.9.1.2-01.js new file mode 100644 index 000000000..9b12e3184 --- /dev/null +++ b/js/src/tests/ecma_3/Date/15.9.1.2-01.js @@ -0,0 +1,29 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 264727; +var summary = '15.9.1.2 - TimeWithinDay(TIME_1900) == 0'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + expect = 0; + actual = TimeWithinDay(TIME_1900); + + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/ecma_3/Date/15.9.4.3.js b/js/src/tests/ecma_3/Date/15.9.4.3.js new file mode 100644 index 000000000..ba4d4d7cb --- /dev/null +++ b/js/src/tests/ecma_3/Date/15.9.4.3.js @@ -0,0 +1,200 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 363578; +var summary = '15.9.4.3 - Date.UTC edge-case arguments.'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + // + + expect = 31; + actual = (new Date(Date.UTC(2006, 0, 0)).getUTCDate()); + reportCompare(expect, actual, summary + ': date 0'); + + expect = 0; + actual = (new Date(Date.UTC(2006, 0, 0, 0)).getUTCHours()); + reportCompare(expect, actual, summary + ': hours 0'); + + expect = 0; + actual = (new Date(Date.UTC(2006, 0, 0, 0, 0)).getUTCMinutes()); + reportCompare(expect, actual, summary + ': minutes 0'); + + expect = 0; + actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, 0)).getUTCSeconds()); + reportCompare(expect, actual, summary + ': seconds 0'); + + expect = 0; + actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, 0, 0)).getUTCMilliseconds()); + reportCompare(expect, actual, summary + ': milliseconds 0'); + + // + + expect = 30; + actual = (new Date(Date.UTC(2006, 0, -1)).getUTCDate()); + reportCompare(expect, actual, summary + ': date -1'); + + expect = 23; + actual = (new Date(Date.UTC(2006, 0, 0, -1)).getUTCHours()); + reportCompare(expect, actual, summary + ': hours -1'); + + expect = 59; + actual = (new Date(Date.UTC(2006, 0, 0, 0, -1)).getUTCMinutes()); + reportCompare(expect, actual, summary + ': minutes -1'); + + expect = 59; + actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, -1)).getUTCSeconds()); + reportCompare(expect, actual, summary + ': seconds -1'); + + expect = 999; + actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, 0, -1)).getUTCMilliseconds()); + reportCompare(expect, actual, summary + ': milliseconds -1'); + + // + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, undefined)).getUTCDate()); + reportCompare(expect, actual, summary + ': date undefined'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, undefined)).getUTCHours()); + reportCompare(expect, actual, summary + ': hours undefined'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, undefined)).getUTCMinutes()); + reportCompare(expect, actual, summary + ': minutes undefined'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, undefined)).getUTCSeconds()); + reportCompare(expect, actual, summary + ': seconds undefined'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, undefined)).getUTCMilliseconds()); + reportCompare(expect, actual, summary + ': milliseconds undefined'); + + // + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, {})).getUTCDate()); + reportCompare(expect, actual, summary + ': date {}'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, {})).getUTCHours()); + reportCompare(expect, actual, summary + ': hours {}'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, {})).getUTCMinutes()); + reportCompare(expect, actual, summary + ': minutes {}'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, {})).getUTCSeconds()); + reportCompare(expect, actual, summary + ': seconds {}'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, {})).getUTCMilliseconds()); + reportCompare(expect, actual, summary + ': milliseconds {}'); + + // + + expect = 31; + actual = (new Date(Date.UTC(2006, 0, null)).getUTCDate()); + reportCompare(expect, actual, summary + ': date null'); + + expect = 0; + actual = (new Date(Date.UTC(2006, 0, 0, null)).getUTCHours()); + reportCompare(expect, actual, summary + ': hours null'); + + expect = 0; + actual = (new Date(Date.UTC(2006, 0, 0, 0, null)).getUTCMinutes()); + reportCompare(expect, actual, summary + ': minutes null'); + + expect = 0; + actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, null)).getUTCSeconds()); + reportCompare(expect, actual, summary + ': seconds null'); + + expect = 0; + actual = (new Date(Date.UTC(2006, 0, 0, 0, 0, 0, null)).getUTCMilliseconds()); + reportCompare(expect, actual, summary + ': milliseconds null'); + + // + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, Infinity)).getUTCDate()); + reportCompare(expect, actual, summary + ': date Infinity'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, Infinity)).getUTCHours()); + reportCompare(expect, actual, summary + ': hours Infinity'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, Infinity)).getUTCMinutes()); + reportCompare(expect, actual, summary + ': minutes Infinity'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, Infinity)).getUTCSeconds()); + reportCompare(expect, actual, summary + ': seconds Infinity'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, Infinity)).getUTCMilliseconds()); + reportCompare(expect, actual, summary + ': milliseconds Infinity'); + + // + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, -Infinity)).getUTCDate()); + reportCompare(expect, actual, summary + ': date -Infinity'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, -Infinity)).getUTCHours()); + reportCompare(expect, actual, summary + ': hours -Infinity'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, -Infinity)).getUTCMinutes()); + reportCompare(expect, actual, summary + ': minutes -Infinity'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, -Infinity)).getUTCSeconds()); + reportCompare(expect, actual, summary + ': seconds -Infinity'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, -Infinity)).getUTCMilliseconds()); + reportCompare(expect, actual, summary + ': milliseconds -Infinity'); + + // + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, NaN)).getUTCDate()); + reportCompare(expect, actual, summary + ': date NaN'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, NaN)).getUTCHours()); + reportCompare(expect, actual, summary + ': hours NaN'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, NaN)).getUTCMinutes()); + reportCompare(expect, actual, summary + ': minutes NaN'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, NaN)).getUTCSeconds()); + reportCompare(expect, actual, summary + ': seconds NaN'); + + expect = true; + actual = isNaN(new Date(Date.UTC(2006, 0, 0, 0, 0, 0, NaN)).getUTCMilliseconds()); + reportCompare(expect, actual, summary + ': milliseconds NaN'); + + exitFunc ('test'); +} diff --git a/js/src/tests/ecma_3/Date/15.9.5.3.js b/js/src/tests/ecma_3/Date/15.9.5.3.js new file mode 100644 index 000000000..e3f072b47 --- /dev/null +++ b/js/src/tests/ecma_3/Date/15.9.5.3.js @@ -0,0 +1,118 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + File Name: 15.9.5.3.js + ECMA Section: 15.9.5.3 Date.prototype.toDateString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "date" + portion of the Date in the current time zone in a convenient, + human-readable form. We can't test the content of the string, + but can verify that the string is parsable by Date.parse + + The toDateString function is not generic; it generates a runtime error + if its 'this' value is not a Date object. Therefore it cannot be transferred + to other kinds of objects for use as a method. + + Author: pschwartau@netscape.com + Date: 14 november 2000 (adapted from ecma/Date/15.9.5.2.js) +*/ + +var SECTION = "15.9.5.3"; +var VERSION = "ECMA_3"; +var TITLE = "Date.prototype.toDateString()"; + +var status = ''; +var actual = ''; +var expect = ''; + + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +// first, some generic tests - + +status = "typeof (now.toDateString())"; +actual = typeof (now.toDateString()); +expect = "string"; +addTestCase(); + +status = "Date.prototype.toDateString.length"; +actual = Date.prototype.toDateString.length; +expect = 0; +addTestCase(); + +/* + * Date.parse is accurate to the second; valueOf() to the millisecond. + * Here we expect them to coincide, as we expect a time of exactly + * midnight - + */ +status = "(Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0"; +actual = (Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0; +expect = true; +addTestCase(); + + + +// 1970 +addDateTestCase(0); +addDateTestCase(TZ_ADJUST); + + +// 1900 +addDateTestCase(TIME_1900); +addDateTestCase(TIME_1900 - TZ_ADJUST); + + +// 2000 +addDateTestCase(TIME_2000); +addDateTestCase(TIME_2000 - TZ_ADJUST); + + +// 29 Feb 2000 +addDateTestCase(UTC_29_FEB_2000); +addDateTestCase(UTC_29_FEB_2000 - 1000); +addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); + + +// 2005 +addDateTestCase(UTC_1_JAN_2005); +addDateTestCase(UTC_1_JAN_2005 - 1000); +addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST); + + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + + +function addTestCase() +{ + new TestCase( + SECTION, + status, + expect, + actual); +} + +function addDateTestCase(date_given_in_milliseconds) +{ + var givenDate = new Date(date_given_in_milliseconds); + + status = 'Date.parse(' + givenDate + ').toDateString())'; + actual = Date.parse(givenDate.toDateString()); + expect = Date.parse(midnight(givenDate)); + addTestCase(); +} + + +function midnight(givenDate) +{ + // midnight on the given date - + return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate()); +} + diff --git a/js/src/tests/ecma_3/Date/15.9.5.4.js b/js/src/tests/ecma_3/Date/15.9.5.4.js new file mode 100644 index 000000000..89a296571 --- /dev/null +++ b/js/src/tests/ecma_3/Date/15.9.5.4.js @@ -0,0 +1,151 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + File Name: 15.9.5.4.js + ECMA Section: 15.9.5.4 Date.prototype.toTimeString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "time" + portion of the Date in the current time zone in a convenient, + human-readable form. We test the content of the string by checking + that d.toDateString() + d.toTimeString() == d.toString() + + Author: pschwartau@netscape.com + Date: 14 november 2000 + Revised: 07 january 2002 because of a change in JS Date format: + + See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) + See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) +*/ +//----------------------------------------------------------------------------- +var SECTION = "15.9.5.4"; +var VERSION = "ECMA_3"; +var TITLE = "Date.prototype.toTimeString()"; + +var status = ''; +var actual = ''; +var expect = ''; +var givenDate; +var year = ''; +var regexp = ''; +var reducedDateString = ''; +var hopeThisIsTimeString = ''; +var cnEmptyString = ''; +var cnERR ='OOPS! FATAL ERROR: no regexp match in extractTimeString()'; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +// first, a couple of generic tests - + +status = "typeof (now.toTimeString())"; +actual = typeof (now.toTimeString()); +expect = "string"; +addTestCase(); + +status = "Date.prototype.toTimeString.length"; +actual = Date.prototype.toTimeString.length; +expect = 0; +addTestCase(); + +// 1970 +addDateTestCase(0); +addDateTestCase(TZ_ADJUST); + + +// 1900 +addDateTestCase(TIME_1900); +addDateTestCase(TIME_1900 - TZ_ADJUST); + + +// 2000 +addDateTestCase(TIME_2000); +addDateTestCase(TIME_2000 - TZ_ADJUST); + + +// 29 Feb 2000 +addDateTestCase(UTC_29_FEB_2000); +addDateTestCase(UTC_29_FEB_2000 - 1000); +addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); + + +// Now +addDateTestCase( TIME_NOW); +addDateTestCase( TIME_NOW - TZ_ADJUST); + + +// 2005 +addDateTestCase(UTC_1_JAN_2005); +addDateTestCase(UTC_1_JAN_2005 - 1000); +addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST); + +//----------------------------------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------------------------------- + +function addTestCase() +{ + new TestCase( + SECTION, + status, + expect, + actual); +} + +function addDateTestCase(date_given_in_milliseconds) +{ + givenDate = new Date(date_given_in_milliseconds); + + status = '(' + givenDate + ').toTimeString()'; + actual = givenDate.toTimeString(); + expect = extractTimeString(givenDate); + addTestCase(); +} + + +/* + * As of 2002-01-07, the format for JavaScript dates changed. + * See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) + * See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) + * + * WAS: Mon Jan 07 13:40:34 GMT-0800 (Pacific Standard Time) 2002 + * NOW: Mon Jan 07 2002 13:40:34 GMT-0800 (Pacific Standard Time) + * + * Thus, use a regexp of the form /date.toDateString()(.*)$/ + * to capture the TimeString into the first backreference - + */ +function extractTimeString(date) +{ + regexp = new RegExp(date.toDateString() + '(.*)' + '$'); + + try + { + hopeThisIsTimeString = date.toString().match(regexp)[1]; + } + catch(e) + { + return cnERR; + } + + // trim any leading or trailing spaces - + return trimL(trimR(hopeThisIsTimeString)); +} + + +function trimL(s) +{ + if (!s) {return cnEmptyString;}; + for (var i = 0; i!=s.length; i++) {if (s[i] != ' ') {break;}} + return s.substring(i); +} + + +function trimR(s) +{ + if (!s) {return cnEmptyString;}; + for (var i = (s.length - 1); i!=-1; i--) {if (s[i] != ' ') {break;}} + return s.substring(0, i+1); +} diff --git a/js/src/tests/ecma_3/Date/15.9.5.5-02.js b/js/src/tests/ecma_3/Date/15.9.5.5-02.js new file mode 100644 index 000000000..56f951784 --- /dev/null +++ b/js/src/tests/ecma_3/Date/15.9.5.5-02.js @@ -0,0 +1,66 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 398485; +var summary = 'Date.prototype.toLocaleString should not clamp year'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + var d; + var y; + var l; + var maxms = 8640000000000000; + + d = new Date(-maxms ); + y = d.getFullYear(); + + actual = y; + expect = -271821; + reportCompare(expect, actual, summary + ': check year'); + + l = d.toLocaleString(); + print(l); + if (this.hasOwnProperty("Intl")) { + // ECMA-402 specifies that toLocaleString uses a proleptic Gregorian + // calender without year 0. + // Also, localized strings usually use era indicators such as "BC" + // instead of minus signs. + expect = Math.abs(y - 1) + ''; + } else { + // ECMA-262 up to edition 5.1 didn't specify toLocaleString; + // the previous implementation assumed a calendar with year 0 and used + // minus sign. + expect = y + ''; + } + actual = l.match(/-?[0-9]{3,}/) + ''; + reportCompare(expect, actual, summary + ': check toLocaleString'); + + d = new Date(maxms ); + y = d.getFullYear(); + l = d.toLocaleString(); + print(l); + + actual = y; + expect = 275760; + reportCompare(expect, actual, summary + ': check year'); + + actual = l.match(new RegExp(y)) + ''; + expect = y + ''; + reportCompare(expect, actual, summary + ': check toLocaleString'); + + exitFunc ('test'); +} diff --git a/js/src/tests/ecma_3/Date/15.9.5.5.js b/js/src/tests/ecma_3/Date/15.9.5.5.js new file mode 100644 index 000000000..27a2df956 --- /dev/null +++ b/js/src/tests/ecma_3/Date/15.9.5.5.js @@ -0,0 +1,111 @@ +// |reftest| random-if(xulRuntime.OS=="Linux") +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: 15.9.5.5.js + ECMA Section: 15.9.5.5 Date.prototype.toLocaleString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "date" + portion of the Date in the current time zone in a convenient, + human-readable form. We can't test the content of the string, + but can verify that the string is parsable by Date.parse + + The toLocaleString function is not generic; it generates a runtime error + if its 'this' value is not a Date object. Therefore it cannot be transferred + to other kinds of objects for use as a method. + + Note: This test isn't supposed to work with a non-English locale per spec. + + Author: pschwartau@netscape.com + Date: 14 november 2000 +*/ + +var SECTION = "15.9.5.5"; +var VERSION = "ECMA_3"; +var TITLE = "Date.prototype.toLocaleString()"; + +var status = ''; +var actual = ''; +var expect = ''; + + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +// first, some generic tests - + +status = "typeof (now.toLocaleString())"; +actual = typeof (now.toLocaleString()); +expect = "string"; +addTestCase(); + +status = "Date.prototype.toLocaleString.length"; +actual = Date.prototype.toLocaleString.length; +expect = 0; +addTestCase(); + +// Date.parse is accurate to the second; valueOf() to the millisecond - +status = "Math.abs(Date.parse(now.toLocaleString('en-US')) - now.valueOf()) < 1000"; +actual = Math.abs(Date.parse(now.toLocaleString('en-US')) - now.valueOf()) < 1000; +expect = true; +addTestCase(); + + + +// 1970 +addDateTestCase(0); +addDateTestCase(TZ_ADJUST); + + +// 1900 +addDateTestCase(TIME_1900); +addDateTestCase(TIME_1900 -TZ_ADJUST); + + +// 2000 +addDateTestCase(TIME_2000); +addDateTestCase(TIME_2000 -TZ_ADJUST); + + +// 29 Feb 2000 +addDateTestCase(UTC_29_FEB_2000); +addDateTestCase(UTC_29_FEB_2000 - 1000); +addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); + + +// 2005 +addDateTestCase(UTC_1_JAN_2005); +addDateTestCase(UTC_1_JAN_2005 - 1000); +addDateTestCase(UTC_1_JAN_2005-TZ_ADJUST); + + + +//----------------------------------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------------------------------- + + +function addTestCase() +{ + AddTestCase( + status, + expect, + actual); +} + + +function addDateTestCase(date_given_in_milliseconds) +{ + var givenDate = new Date(date_given_in_milliseconds); + + status = 'Date.parse(' + givenDate + ').toLocaleString("en-US"))'; + actual = Date.parse(givenDate.toLocaleString("en-US")); + expect = date_given_in_milliseconds; + addTestCase(); +} + diff --git a/js/src/tests/ecma_3/Date/15.9.5.6.js b/js/src/tests/ecma_3/Date/15.9.5.6.js new file mode 100644 index 000000000..6d091b600 --- /dev/null +++ b/js/src/tests/ecma_3/Date/15.9.5.6.js @@ -0,0 +1,119 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/** + File Name: 15.9.5.6.js + ECMA Section: 15.9.5.6 Date.prototype.toLocaleDateString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "date" + portion of the Date in the current time zone in a convenient, + human-readable form. We can't test the content of the string, + but can verify that the string is parsable by Date.parse + + The toLocaleDateString function is not generic; it generates a runtime error + if its 'this' value is not a Date object. Therefore it cannot be transferred + to other kinds of objects for use as a method. + + Note: This test isn't supposed to work with a non-English locale per spec. + + Author: pschwartau@netscape.com + Date: 14 november 2000 +*/ + +var SECTION = "15.9.5.6"; +var VERSION = "ECMA_3"; +var TITLE = "Date.prototype.toLocaleDateString()"; + +var status = ''; +var actual = ''; +var expect = ''; + + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +// first, some generic tests - + +status = "typeof (now.toLocaleDateString())"; +actual = typeof (now.toLocaleDateString()); +expect = "string"; +addTestCase(); + +status = "Date.prototype.toLocaleDateString.length"; +actual = Date.prototype.toLocaleDateString.length; +expect = 0; +addTestCase(); + +/* Date.parse is accurate to the second; valueOf() to the millisecond. + Here we expect them to coincide, as we expect a time of exactly midnight - */ +status = "(Date.parse(now.toLocaleDateString('en-US')) - (midnight(now)).valueOf()) == 0"; +actual = (Date.parse(now.toLocaleDateString('en-US')) - (midnight(now)).valueOf()) == 0; +expect = true; +addTestCase(); + + + +// 1970 +addDateTestCase(0); +addDateTestCase(TZ_ADJUST); + + +// 1900 +addDateTestCase(TIME_1900); +addDateTestCase(TIME_1900 - TZ_ADJUST); + + +// 2000 +addDateTestCase(TIME_2000); +addDateTestCase(TIME_2000 - TZ_ADJUST); + + +// 29 Feb 2000 +addDateTestCase(UTC_29_FEB_2000); +addDateTestCase(UTC_29_FEB_2000 - 1000); +addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); + + +// 2005 +addDateTestCase(UTC_1_JAN_2005); +addDateTestCase(UTC_1_JAN_2005 - 1000); +addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST); + + + +//----------------------------------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------------------------------- + + +function addTestCase() +{ + new TestCase( + "unknown-test-name", + status, + expect, + actual); +} + + +function addDateTestCase(date_given_in_milliseconds) +{ + var givenDate = new Date(date_given_in_milliseconds); + + status = 'Date.parse(' + givenDate + ').toLocaleDateString("en-US"))'; + actual = Date.parse(givenDate.toLocaleDateString("en-US")); + expect = Date.parse(midnight(givenDate)); + addTestCase(); +} + + +function midnight(givenDate) +{ + // midnight on the given date - + return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate()); +} + diff --git a/js/src/tests/ecma_3/Date/15.9.5.7.js b/js/src/tests/ecma_3/Date/15.9.5.7.js new file mode 100644 index 000000000..f116f3e65 --- /dev/null +++ b/js/src/tests/ecma_3/Date/15.9.5.7.js @@ -0,0 +1,108 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + File Name: 15.9.5.7.js + ECMA Section: 15.9.5.7 Date.prototype.toLocaleTimeString() + Description: + This function returns a string value. The contents of the string are + implementation dependent, but are intended to represent the "time" + portion of the Date in the current time zone in a convenient, + human-readable form. We test the content of the string by checking + that + + new Date(d.toDateString() + " " + d.toLocaleTimeString()) == d + + Author: pschwartau@netscape.com + Date: 14 november 2000 + Revised: 07 january 2002 because of a change in JS Date format: + Revised: 21 November 2005 since the string comparison stuff is horked. + bclary + + See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) + See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) +*/ +//----------------------------------------------------------------------------- +var SECTION = "15.9.5.7"; +var VERSION = "ECMA_3"; +var TITLE = "Date.prototype.toLocaleTimeString()"; + +var status = ''; +var actual = ''; +var expect = ''; +var givenDate; +var year = ''; +var regexp = ''; +var TimeString = ''; +var reducedDateString = ''; +var hopeThisIsLocaleTimeString = ''; +var cnERR ='OOPS! FATAL ERROR: no regexp match in extractLocaleTimeString()'; + +startTest(); +writeHeaderToLog( SECTION + " "+ TITLE); + +// first, a couple generic tests - + +status = "typeof (now.toLocaleTimeString())"; +actual = typeof (now.toLocaleTimeString()); +expect = "string"; +addTestCase(); + +status = "Date.prototype.toLocaleTimeString.length"; +actual = Date.prototype.toLocaleTimeString.length; +expect = 0; +addTestCase(); + +// 1970 +addDateTestCase(0); +addDateTestCase(TZ_ADJUST); + +// 1900 +addDateTestCase(TIME_1900); +addDateTestCase(TIME_1900 - TZ_ADJUST); + +// 2000 +addDateTestCase(TIME_2000); +addDateTestCase(TIME_2000 - TZ_ADJUST); + +// 29 Feb 2000 +addDateTestCase(UTC_29_FEB_2000); +addDateTestCase(UTC_29_FEB_2000 - 1000); +addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); + +// Now +addDateTestCase( TIME_NOW); +addDateTestCase( TIME_NOW - TZ_ADJUST); + +// 2005 +addDateTestCase(UTC_1_JAN_2005); +addDateTestCase(UTC_1_JAN_2005 - 1000); +addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST); + +test(); + +function addTestCase() +{ + new TestCase( + SECTION, + status, + expect, + actual); +} + + +function addDateTestCase(date_given_in_milliseconds) +{ + var s = 'new Date(' + date_given_in_milliseconds + ')'; + givenDate = new Date(date_given_in_milliseconds); + + status = 'd = ' + s + + '; d == new Date(d.toDateString() + " " + d.toLocaleTimeString())'; + expect = givenDate.toString(); + actual = new Date(givenDate.toDateString() + + ' ' + givenDate.toLocaleTimeString()).toString(); + addTestCase(); +} + diff --git a/js/src/tests/ecma_3/Date/browser.js b/js/src/tests/ecma_3/Date/browser.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/js/src/tests/ecma_3/Date/browser.js diff --git a/js/src/tests/ecma_3/Date/regress-452786.js b/js/src/tests/ecma_3/Date/regress-452786.js new file mode 100644 index 000000000..a140a844b --- /dev/null +++ b/js/src/tests/ecma_3/Date/regress-452786.js @@ -0,0 +1,33 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 452786; +var summary = 'Do not crash with (new Date()).getMonth.call(new Function())'; +var actual = ''; +var expect = ''; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + enterFunc ('test'); + printBugNumber(BUGNUMBER); + printStatus (summary); + + try + { + (new Date()).getMonth.call(new Function()); + } + catch(ex) + { + } + reportCompare(expect, actual, summary); + + exitFunc ('test'); +} diff --git a/js/src/tests/ecma_3/Date/shell.js b/js/src/tests/ecma_3/Date/shell.js new file mode 100644 index 000000000..bc01272b1 --- /dev/null +++ b/js/src/tests/ecma_3/Date/shell.js @@ -0,0 +1,530 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +/* + * Date functions used by tests in Date suite + * + */ +var msPerDay = 86400000; +var HoursPerDay = 24; +var MinutesPerHour = 60; +var SecondsPerMinute = 60; +var msPerSecond = 1000; +var msPerMinute = 60000; // msPerSecond * SecondsPerMinute +var msPerHour = 3600000; // msPerMinute * MinutesPerHour +var TZ_DIFF = getTimeZoneDiff(); // offset of tester's timezone from UTC +var TZ_ADJUST = TZ_DIFF * msPerHour; +var TZ_PST = -8; // offset of Pacific Standard Time from UTC +var PST_DIFF = TZ_DIFF - TZ_PST; // offset of tester's timezone from PST +var TIME_1970 = 0; +var TIME_2000 = 946684800000; +var TIME_1900 = -2208988800000; +var UTC_29_FEB_2000 = TIME_2000 + 31*msPerDay + 28*msPerDay; +var UTC_1_JAN_2005 = TIME_2000 + TimeInYear(2000) + TimeInYear(2001) + + TimeInYear(2002) + TimeInYear(2003) + TimeInYear(2004); +var now = new Date(); +var TIME_NOW = now.valueOf(); //valueOf() is to accurate to the millisecond + //Date.parse() is accurate only to the second + +/* + * Originally, the test suite used a hard-coded value TZ_DIFF = -8. + * But that was only valid for testers in the Pacific Standard Time Zone! + * We calculate the proper number dynamically for any tester. We just + * have to be careful not to use a date subject to Daylight Savings Time... + */ +function getTimeZoneDiff() +{ + return -((new Date(2000, 1, 1)).getTimezoneOffset())/60; +} + + +/* + * Date test "ResultArrays" are hard-coded for Pacific Standard Time. + * We must adjust them for the tester's own timezone - + */ +function adjustResultArray(ResultArray, msMode) +{ + // If the tester's system clock is in PST, no need to continue - + if (!PST_DIFF) {return;} + + /* The date testcases instantiate Date objects in two different ways: + * + * millisecond mode: e.g. dt = new Date(10000000); + * year-month-day mode: dt = new Date(2000, 5, 1, ...); + * + * In the first case, the date is measured from Time 0 in Greenwich (i.e. UTC). + * In the second case, it is measured with reference to the tester's local timezone. + * + * In the first case we must correct those values expected for local measurements, + * like dt.getHours() etc. No correction is necessary for dt.getUTCHours() etc. + * + * In the second case, it is exactly the other way around - + */ + if (msMode) + { + // The hard-coded UTC milliseconds from Time 0 derives from a UTC date. + // Shift to the right by the offset between UTC and the tester. + var t = ResultArray[TIME] + TZ_DIFF*msPerHour; + + // Use our date arithmetic functions to determine the local hour, day, etc. + ResultArray[HOURS] = HourFromTime(t); + ResultArray[DAY] = WeekDay(t); + ResultArray[DATE] = DateFromTime(t); + ResultArray[MONTH] = MonthFromTime(t); + ResultArray[YEAR] = YearFromTime(t); + } + else + { + // The hard-coded UTC milliseconds from Time 0 derives from a PST date. + // Shift to the left by the offset between PST and the tester. + var t = ResultArray[TIME] - PST_DIFF*msPerHour; + + // Use our date arithmetic functions to determine the UTC hour, day, etc. + ResultArray[TIME] = t; + ResultArray[UTC_HOURS] = HourFromTime(t); + ResultArray[UTC_DAY] = WeekDay(t); + ResultArray[UTC_DATE] = DateFromTime(t); + ResultArray[UTC_MONTH] = MonthFromTime(t); + ResultArray[UTC_YEAR] = YearFromTime(t); + } +} + + +function Day( t ) { + return ( Math.floor(t/msPerDay ) ); +} +function DaysInYear( y ) { + if ( y % 4 != 0 ) { + return 365; + } + if ( (y % 4 == 0) && (y % 100 != 0) ) { + return 366; + } + if ( (y % 100 == 0) && (y % 400 != 0) ) { + return 365; + } + if ( (y % 400 == 0) ){ + return 366; + } else { + return "ERROR: DaysInYear(" + y + ") case not covered"; + } +} +function TimeInYear( y ) { + return ( DaysInYear(y) * msPerDay ); +} +function DayNumber( t ) { + return ( Math.floor( t / msPerDay ) ); +} +function TimeWithinDay( t ) { + + var r = t % msPerDay; + + if (r < 0) + { + r += msPerDay; + } + return r; + +} +function YearNumber( t ) { +} +function TimeFromYear( y ) { + return ( msPerDay * DayFromYear(y) ); +} +function DayFromYear( y ) { + return ( 365*(y-1970) + + Math.floor((y-1969)/4) - + Math.floor((y-1901)/100) + + Math.floor((y-1601)/400) ); +} +function InLeapYear( t ) { + if ( DaysInYear(YearFromTime(t)) == 365 ) { + return 0; + } + if ( DaysInYear(YearFromTime(t)) == 366 ) { + return 1; + } else { + return "ERROR: InLeapYear("+ t + ") case not covered"; + } +} +function YearFromTime( t ) { + t = Number( t ); + var sign = ( t < 0 ) ? -1 : 1; + var year = ( sign < 0 ) ? 1969 : 1970; + for ( var timeToTimeZero = t; ; ) { + // subtract the current year's time from the time that's left. + timeToTimeZero -= sign * TimeInYear(year) + + // if there's less than the current year's worth of time left, then break. + if ( sign < 0 ) { + if ( sign * timeToTimeZero <= 0 ) { + break; + } else { + year += sign; + } + } else { + if ( sign * timeToTimeZero < 0 ) { + break; + } else { + year += sign; + } + } + } + return ( year ); +} +function MonthFromTime( t ) { + // i know i could use switch but i'd rather not until it's part of ECMA + var day = DayWithinYear( t ); + var leap = InLeapYear(t); + + if ( (0 <= day) && (day < 31) ) { + return 0; + } + if ( (31 <= day) && (day < (59+leap)) ) { + return 1; + } + if ( ((59+leap) <= day) && (day < (90+leap)) ) { + return 2; + } + if ( ((90+leap) <= day) && (day < (120+leap)) ) { + return 3; + } + if ( ((120+leap) <= day) && (day < (151+leap)) ) { + return 4; + } + if ( ((151+leap) <= day) && (day < (181+leap)) ) { + return 5; + } + if ( ((181+leap) <= day) && (day < (212+leap)) ) { + return 6; + } + if ( ((212+leap) <= day) && (day < (243+leap)) ) { + return 7; + } + if ( ((243+leap) <= day) && (day < (273+leap)) ) { + return 8; + } + if ( ((273+leap) <= day) && (day < (304+leap)) ) { + return 9; + } + if ( ((304+leap) <= day) && (day < (334+leap)) ) { + return 10; + } + if ( ((334+leap) <= day) && (day < (365+leap)) ) { + return 11; + } else { + return "ERROR: MonthFromTime("+t+") not known"; + } +} +function DayWithinYear( t ) { + return( Day(t) - DayFromYear(YearFromTime(t))); +} +function DateFromTime( t ) { + var day = DayWithinYear(t); + var month = MonthFromTime(t); + + if ( month == 0 ) { + return ( day + 1 ); + } + if ( month == 1 ) { + return ( day - 30 ); + } + if ( month == 2 ) { + return ( day - 58 - InLeapYear(t) ); + } + if ( month == 3 ) { + return ( day - 89 - InLeapYear(t)); + } + if ( month == 4 ) { + return ( day - 119 - InLeapYear(t)); + } + if ( month == 5 ) { + return ( day - 150- InLeapYear(t)); + } + if ( month == 6 ) { + return ( day - 180- InLeapYear(t)); + } + if ( month == 7 ) { + return ( day - 211- InLeapYear(t)); + } + if ( month == 8 ) { + return ( day - 242- InLeapYear(t)); + } + if ( month == 9 ) { + return ( day - 272- InLeapYear(t)); + } + if ( month == 10 ) { + return ( day - 303- InLeapYear(t)); + } + if ( month == 11 ) { + return ( day - 333- InLeapYear(t)); + } + + return ("ERROR: DateFromTime("+t+") not known" ); +} +function WeekDay( t ) { + var weekday = (Day(t)+4) % 7; + return( weekday < 0 ? 7 + weekday : weekday ); +} + +// missing daylight savings time adjustment + +function HourFromTime( t ) { + var h = Math.floor( t / msPerHour ) % HoursPerDay; + return ( (h<0) ? HoursPerDay + h : h ); +} +function MinFromTime( t ) { + var min = Math.floor( t / msPerMinute ) % MinutesPerHour; + return( ( min < 0 ) ? MinutesPerHour + min : min ); +} +function SecFromTime( t ) { + var sec = Math.floor( t / msPerSecond ) % SecondsPerMinute; + return ( (sec < 0 ) ? SecondsPerMinute + sec : sec ); +} +function msFromTime( t ) { + var ms = t % msPerSecond; + return ( (ms < 0 ) ? msPerSecond + ms : ms ); +} +function LocalTZA() { + return ( TZ_DIFF * msPerHour ); +} +function UTC( t ) { + return ( t - LocalTZA() - DaylightSavingTA(t - LocalTZA()) ); +} + +function DaylightSavingTA( t ) { + t = t - LocalTZA(); + + var dst_start = GetDSTStart(t); + var dst_end = GetDSTEnd(t); + + if ( t >= dst_start && t < dst_end ) + return msPerHour; + + return 0; +} + +function GetFirstSundayInMonth( t, m ) { + var year = YearFromTime(t); + var leap = InLeapYear(t); + +// month m 0..11 +// april == 3 +// march == 2 + + // set time to first day of month m + var time = TimeFromYear(year); + for (var i = 0; i < m; ++i) + { + time += TimeInMonth(i, leap); + } + + for ( var first_sunday = time; WeekDay(first_sunday) > 0; + first_sunday += msPerDay ) + { + ; + } + + return first_sunday; +} + +function GetLastSundayInMonth( t, m ) { + var year = YearFromTime(t); + var leap = InLeapYear(t); + +// month m 0..11 +// april == 3 +// march == 2 + + // first day of following month + var time = TimeFromYear(year); + for (var i = 0; i <= m; ++i) + { + time += TimeInMonth(i, leap); + } + // prev day == last day of month + time -= msPerDay; + + for ( var last_sunday = time; WeekDay(last_sunday) > 0; + last_sunday -= msPerDay ) + { + ; + } + return last_sunday; +} + +/* + 15.9.1.9 Daylight Saving Time Adjustment + + The implementation of ECMAScript should not try to determine whether + the exact time was subject to daylight saving time, but just whether + daylight saving time would have been in effect if the current + daylight saving time algorithm had been used at the time. This avoids + complications such as taking into account the years that the locale + observed daylight saving time year round. +*/ + +/* + US DST algorithm + + Before 2007, DST starts first Sunday in April at 2 AM and ends last + Sunday in October at 2 AM + + Starting in 2007, DST starts second Sunday in March at 2 AM and ends + first Sunday in November at 2 AM + + Note that different operating systems behave differently. + + Fully patched Windows XP uses the 2007 algorithm for all dates while + fully patched Fedora Core 6 and RHEL 4 Linux use the algorithm in + effect at the time. + + Since pre-2007 DST is a subset of 2007 DST rules, this only affects + tests that occur in the period Mar-Apr and Oct-Nov where the two + algorithms do not agree. + +*/ + +function GetDSTStart( t ) +{ + return (GetFirstSundayInMonth(t, 2) + 7*msPerDay + 2*msPerHour - LocalTZA()); +} + +function GetDSTEnd( t ) +{ + return (GetFirstSundayInMonth(t, 10) + 2*msPerHour - LocalTZA()); +} + +function GetOldDSTStart( t ) +{ + return (GetFirstSundayInMonth(t, 3) + 2*msPerHour - LocalTZA()); +} + +function GetOldDSTEnd( t ) +{ + return (GetLastSundayInMonth(t, 9) + 2*msPerHour - LocalTZA()); +} + +function LocalTime( t ) { + return ( t + LocalTZA() + DaylightSavingTA(t) ); +} +function MakeTime( hour, min, sec, ms ) { + if ( isNaN( hour ) || isNaN( min ) || isNaN( sec ) || isNaN( ms ) ) { + return Number.NaN; + } + + hour = ToInteger(hour); + min = ToInteger( min); + sec = ToInteger( sec); + ms = ToInteger( ms ); + + return( (hour*msPerHour) + (min*msPerMinute) + + (sec*msPerSecond) + ms ); +} +function MakeDay( year, month, date ) { + if ( isNaN(year) || isNaN(month) || isNaN(date) ) { + return Number.NaN; + } + year = ToInteger(year); + month = ToInteger(month); + date = ToInteger(date ); + + var sign = ( year < 1970 ) ? -1 : 1; + var t = ( year < 1970 ) ? 1 : 0; + var y = ( year < 1970 ) ? 1969 : 1970; + + var result5 = year + Math.floor( month/12 ); + var result6 = month % 12; + + if ( year < 1970 ) { + for ( y = 1969; y >= year; y += sign ) { + t += sign * TimeInYear(y); + } + } else { + for ( y = 1970 ; y < year; y += sign ) { + t += sign * TimeInYear(y); + } + } + + var leap = InLeapYear( t ); + + for ( var m = 0; m < month; m++ ) { + t += TimeInMonth( m, leap ); + } + + if ( YearFromTime(t) != result5 ) { + return Number.NaN; + } + if ( MonthFromTime(t) != result6 ) { + return Number.NaN; + } + if ( DateFromTime(t) != 1 ) { + return Number.NaN; + } + + return ( (Day(t)) + date - 1 ); +} +function TimeInMonth( month, leap ) { + // september april june november + // jan 0 feb 1 mar 2 apr 3 may 4 june 5 jul 6 + // aug 7 sep 8 oct 9 nov 10 dec 11 + + if ( month == 3 || month == 5 || month == 8 || month == 10 ) { + return ( 30*msPerDay ); + } + + // all the rest + if ( month == 0 || month == 2 || month == 4 || month == 6 || + month == 7 || month == 9 || month == 11 ) { + return ( 31*msPerDay ); + } + + // save february + return ( (leap == 0) ? 28*msPerDay : 29*msPerDay ); +} +function MakeDate( day, time ) { + if ( day == Number.POSITIVE_INFINITY || + day == Number.NEGATIVE_INFINITY ) { + return Number.NaN; + } + if ( time == Number.POSITIVE_INFINITY || + time == Number.NEGATIVE_INFINITY ) { + return Number.NaN; + } + return ( day * msPerDay ) + time; +} +function TimeClip( t ) { + if ( isNaN( t ) ) { + return ( Number.NaN ); + } + if ( Math.abs( t ) > 8.64e15 ) { + return ( Number.NaN ); + } + + return ( ToInteger( t ) ); +} +function ToInteger( t ) { + t = Number( t ); + + if ( isNaN( t ) ){ + return ( Number.NaN ); + } + if ( t == 0 || t == -0 || + t == Number.POSITIVE_INFINITY || t == Number.NEGATIVE_INFINITY ) { + return 0; + } + + var sign = ( t < 0 ) ? -1 : 1; + + return ( sign * Math.floor( Math.abs( t ) ) ); +} +function Enumerate ( o ) { + var p; + for ( p in o ) { + print( p +": " + o[p] ); + } +} + |