michael@0: // |reftest| random-if(xulRuntime.OS=="Linux") michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 15.9.5.5.js michael@0: ECMA Section: 15.9.5.5 Date.prototype.toLocaleString() michael@0: Description: michael@0: This function returns a string value. The contents of the string are michael@0: implementation dependent, but are intended to represent the "date" michael@0: portion of the Date in the current time zone in a convenient, michael@0: human-readable form. We can't test the content of the string, michael@0: but can verify that the string is parsable by Date.parse michael@0: michael@0: The toLocaleString function is not generic; it generates a runtime error michael@0: if its 'this' value is not a Date object. Therefore it cannot be transferred michael@0: to other kinds of objects for use as a method. michael@0: michael@0: Note: This test isn't supposed to work with a non-English locale per spec. michael@0: michael@0: Author: pschwartau@netscape.com michael@0: Date: 14 november 2000 michael@0: */ michael@0: michael@0: var SECTION = "15.9.5.5"; michael@0: var VERSION = "ECMA_3"; michael@0: var TITLE = "Date.prototype.toLocaleString()"; michael@0: michael@0: var status = ''; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: // first, some generic tests - michael@0: michael@0: status = "typeof (now.toLocaleString())"; michael@0: actual = typeof (now.toLocaleString()); michael@0: expect = "string"; michael@0: addTestCase(); michael@0: michael@0: status = "Date.prototype.toLocaleString.length"; michael@0: actual = Date.prototype.toLocaleString.length; michael@0: expect = 0; michael@0: addTestCase(); michael@0: michael@0: // Date.parse is accurate to the second; valueOf() to the millisecond - michael@0: status = "Math.abs(Date.parse(now.toLocaleString()) - now.valueOf()) < 1000"; michael@0: actual = Math.abs(Date.parse(now.toLocaleString()) - now.valueOf()) < 1000; michael@0: expect = true; michael@0: addTestCase(); michael@0: michael@0: michael@0: michael@0: // 1970 michael@0: addDateTestCase(0); michael@0: addDateTestCase(TZ_ADJUST); michael@0: michael@0: michael@0: // 1900 michael@0: addDateTestCase(TIME_1900); michael@0: addDateTestCase(TIME_1900 -TZ_ADJUST); michael@0: michael@0: michael@0: // 2000 michael@0: addDateTestCase(TIME_2000); michael@0: addDateTestCase(TIME_2000 -TZ_ADJUST); michael@0: michael@0: michael@0: // 29 Feb 2000 michael@0: addDateTestCase(UTC_29_FEB_2000); michael@0: addDateTestCase(UTC_29_FEB_2000 - 1000); michael@0: addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); michael@0: michael@0: michael@0: // 2005 michael@0: addDateTestCase(UTC_1_JAN_2005); michael@0: addDateTestCase(UTC_1_JAN_2005 - 1000); michael@0: addDateTestCase(UTC_1_JAN_2005-TZ_ADJUST); michael@0: michael@0: michael@0: michael@0: //----------------------------------------------------------------------------------------------------- michael@0: test(); michael@0: //----------------------------------------------------------------------------------------------------- michael@0: michael@0: michael@0: function addTestCase() michael@0: { michael@0: AddTestCase( michael@0: status, michael@0: expect, michael@0: actual); michael@0: } michael@0: michael@0: michael@0: function addDateTestCase(date_given_in_milliseconds) michael@0: { michael@0: var givenDate = new Date(date_given_in_milliseconds); michael@0: michael@0: status = 'Date.parse(' + givenDate + ').toLocaleString())'; michael@0: actual = Date.parse(givenDate.toLocaleString()); michael@0: expect = date_given_in_milliseconds; michael@0: addTestCase(); michael@0: } michael@0: