1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/Date/15.9.5.7.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,108 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/** 1.10 + File Name: 15.9.5.7.js 1.11 + ECMA Section: 15.9.5.7 Date.prototype.toLocaleTimeString() 1.12 + Description: 1.13 + This function returns a string value. The contents of the string are 1.14 + implementation dependent, but are intended to represent the "time" 1.15 + portion of the Date in the current time zone in a convenient, 1.16 + human-readable form. We test the content of the string by checking 1.17 + that 1.18 + 1.19 + new Date(d.toDateString() + " " + d.toLocaleTimeString()) == d 1.20 + 1.21 + Author: pschwartau@netscape.com 1.22 + Date: 14 november 2000 1.23 + Revised: 07 january 2002 because of a change in JS Date format: 1.24 + Revised: 21 November 2005 since the string comparison stuff is horked. 1.25 + bclary 1.26 + 1.27 + See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) 1.28 + See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) 1.29 +*/ 1.30 +//----------------------------------------------------------------------------- 1.31 +var SECTION = "15.9.5.7"; 1.32 +var VERSION = "ECMA_3"; 1.33 +var TITLE = "Date.prototype.toLocaleTimeString()"; 1.34 + 1.35 +var status = ''; 1.36 +var actual = ''; 1.37 +var expect = ''; 1.38 +var givenDate; 1.39 +var year = ''; 1.40 +var regexp = ''; 1.41 +var TimeString = ''; 1.42 +var reducedDateString = ''; 1.43 +var hopeThisIsLocaleTimeString = ''; 1.44 +var cnERR ='OOPS! FATAL ERROR: no regexp match in extractLocaleTimeString()'; 1.45 + 1.46 +startTest(); 1.47 +writeHeaderToLog( SECTION + " "+ TITLE); 1.48 + 1.49 +// first, a couple generic tests - 1.50 + 1.51 +status = "typeof (now.toLocaleTimeString())"; 1.52 +actual = typeof (now.toLocaleTimeString()); 1.53 +expect = "string"; 1.54 +addTestCase(); 1.55 + 1.56 +status = "Date.prototype.toLocaleTimeString.length"; 1.57 +actual = Date.prototype.toLocaleTimeString.length; 1.58 +expect = 0; 1.59 +addTestCase(); 1.60 + 1.61 +// 1970 1.62 +addDateTestCase(0); 1.63 +addDateTestCase(TZ_ADJUST); 1.64 + 1.65 +// 1900 1.66 +addDateTestCase(TIME_1900); 1.67 +addDateTestCase(TIME_1900 - TZ_ADJUST); 1.68 + 1.69 +// 2000 1.70 +addDateTestCase(TIME_2000); 1.71 +addDateTestCase(TIME_2000 - TZ_ADJUST); 1.72 + 1.73 +// 29 Feb 2000 1.74 +addDateTestCase(UTC_29_FEB_2000); 1.75 +addDateTestCase(UTC_29_FEB_2000 - 1000); 1.76 +addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); 1.77 + 1.78 +// Now 1.79 +addDateTestCase( TIME_NOW); 1.80 +addDateTestCase( TIME_NOW - TZ_ADJUST); 1.81 + 1.82 +// 2005 1.83 +addDateTestCase(UTC_1_JAN_2005); 1.84 +addDateTestCase(UTC_1_JAN_2005 - 1000); 1.85 +addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST); 1.86 + 1.87 +test(); 1.88 + 1.89 +function addTestCase() 1.90 +{ 1.91 + new TestCase( 1.92 + SECTION, 1.93 + status, 1.94 + expect, 1.95 + actual); 1.96 +} 1.97 + 1.98 + 1.99 +function addDateTestCase(date_given_in_milliseconds) 1.100 +{ 1.101 + var s = 'new Date(' + date_given_in_milliseconds + ')'; 1.102 + givenDate = new Date(date_given_in_milliseconds); 1.103 + 1.104 + status = 'd = ' + s + 1.105 + '; d == new Date(d.toDateString() + " " + d.toLocaleTimeString())'; 1.106 + expect = givenDate.toString(); 1.107 + actual = new Date(givenDate.toDateString() + 1.108 + ' ' + givenDate.toLocaleTimeString()).toString(); 1.109 + addTestCase(); 1.110 +} 1.111 +