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: File Name: 15.9.5.7.js michael@0: ECMA Section: 15.9.5.7 Date.prototype.toLocaleTimeString() 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 "time" michael@0: portion of the Date in the current time zone in a convenient, michael@0: human-readable form. We test the content of the string by checking michael@0: that michael@0: michael@0: new Date(d.toDateString() + " " + d.toLocaleTimeString()) == d michael@0: michael@0: Author: pschwartau@netscape.com michael@0: Date: 14 november 2000 michael@0: Revised: 07 january 2002 because of a change in JS Date format: michael@0: Revised: 21 November 2005 since the string comparison stuff is horked. michael@0: bclary michael@0: michael@0: See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) michael@0: See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var SECTION = "15.9.5.7"; michael@0: var VERSION = "ECMA_3"; michael@0: var TITLE = "Date.prototype.toLocaleTimeString()"; michael@0: michael@0: var status = ''; michael@0: var actual = ''; michael@0: var expect = ''; michael@0: var givenDate; michael@0: var year = ''; michael@0: var regexp = ''; michael@0: var TimeString = ''; michael@0: var reducedDateString = ''; michael@0: var hopeThisIsLocaleTimeString = ''; michael@0: var cnERR ='OOPS! FATAL ERROR: no regexp match in extractLocaleTimeString()'; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: // first, a couple generic tests - michael@0: michael@0: status = "typeof (now.toLocaleTimeString())"; michael@0: actual = typeof (now.toLocaleTimeString()); michael@0: expect = "string"; michael@0: addTestCase(); michael@0: michael@0: status = "Date.prototype.toLocaleTimeString.length"; michael@0: actual = Date.prototype.toLocaleTimeString.length; michael@0: expect = 0; michael@0: addTestCase(); michael@0: michael@0: // 1970 michael@0: addDateTestCase(0); michael@0: addDateTestCase(TZ_ADJUST); michael@0: michael@0: // 1900 michael@0: addDateTestCase(TIME_1900); michael@0: addDateTestCase(TIME_1900 - TZ_ADJUST); michael@0: michael@0: // 2000 michael@0: addDateTestCase(TIME_2000); michael@0: addDateTestCase(TIME_2000 - TZ_ADJUST); 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: // Now michael@0: addDateTestCase( TIME_NOW); michael@0: addDateTestCase( TIME_NOW - TZ_ADJUST); 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: test(); michael@0: michael@0: function addTestCase() michael@0: { michael@0: new TestCase( michael@0: SECTION, 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 s = 'new Date(' + date_given_in_milliseconds + ')'; michael@0: givenDate = new Date(date_given_in_milliseconds); michael@0: michael@0: status = 'd = ' + s + michael@0: '; d == new Date(d.toDateString() + " " + d.toLocaleTimeString())'; michael@0: expect = givenDate.toString(); michael@0: actual = new Date(givenDate.toDateString() + michael@0: ' ' + givenDate.toLocaleTimeString()).toString(); michael@0: addTestCase(); michael@0: } michael@0: