15.9.5.7.js (3243B)
1 // |reftest| skip-if(winWidget) -- Windows doesn't accept IANA names for the TZ env variable 2 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 /** 8 File Name: 15.9.5.7.js 9 ECMA Section: 15.9.5.7 Date.prototype.toLocaleTimeString() 10 Description: 11 This function returns a string value. The contents of the string are 12 implementation dependent, but are intended to represent the "time" 13 portion of the Date in the current time zone in a convenient, 14 human-readable form. We test the content of the string by checking 15 that 16 17 new Date(d.toDateString() + " " + d.toLocaleTimeString()) == d 18 19 Author: pschwartau@netscape.com 20 Date: 14 november 2000 21 Revised: 07 january 2002 because of a change in JS Date format: 22 Revised: 21 November 2005 since the string comparison stuff is horked. 23 bclary 24 25 See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey) 26 See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino) 27 */ 28 29 var SECTION = "15.9.5.7"; 30 var TITLE = "Date.prototype.toLocaleTimeString()"; 31 32 var status = ''; 33 var actual = ''; 34 var expect = ''; 35 var givenDate; 36 var year = ''; 37 var regexp = ''; 38 var TimeString = ''; 39 var reducedDateString = ''; 40 var hopeThisIsLocaleTimeString = ''; 41 var cnERR = 'OOPS! FATAL ERROR: no regexp match in extractLocaleTimeString()'; 42 43 writeHeaderToLog(SECTION + " " + TITLE); 44 45 inTimeZone("PST", () => { 46 var now = new Date(); 47 48 // valueOf() is to accurate to the millisecond, 49 // Date.parse() is accurate only to the second 50 var TIME_NOW = now.valueOf(); 51 52 // first, a couple generic tests - 53 54 status = "typeof (now.toLocaleTimeString())"; 55 actual = typeof (now.toLocaleTimeString()); 56 expect = "string"; 57 addTestCase(); 58 59 status = "Date.prototype.toLocaleTimeString.length"; 60 actual = Date.prototype.toLocaleTimeString.length; 61 expect = 0; 62 addTestCase(); 63 64 // 1970 65 addDateTestCase(0); 66 addDateTestCase(TZ_ADJUST); 67 68 // 1900 69 addDateTestCase(UTC_01_JAN_1900); 70 addDateTestCase(UTC_01_JAN_1900 - TZ_ADJUST); 71 72 // 2000 73 addDateTestCase(UTC_01_JAN_2000); 74 addDateTestCase(UTC_01_JAN_2000 - TZ_ADJUST); 75 76 // 29 Feb 2000 77 addDateTestCase(UTC_29_FEB_2000); 78 addDateTestCase(UTC_29_FEB_2000 - 1000); 79 addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); 80 81 // Now 82 addDateTestCase(TIME_NOW); 83 addDateTestCase(TIME_NOW - TZ_ADJUST); 84 85 // 2005 86 addDateTestCase(UTC_01_JAN_2005); 87 addDateTestCase(UTC_01_JAN_2005 - 1000); 88 addDateTestCase(UTC_01_JAN_2005 - TZ_ADJUST); 89 90 test(); 91 92 function addTestCase() { 93 new TestCase( 94 status, 95 expect, 96 actual); 97 } 98 99 function addDateTestCase(date_given_in_milliseconds) { 100 var s = 'new Date(' + date_given_in_milliseconds + ')'; 101 givenDate = new Date(date_given_in_milliseconds); 102 103 status = 'd = ' + s + 104 '; d == new Date(d.toDateString() + " " + d.toLocaleTimeString())'; 105 expect = givenDate.toString(); 106 actual = new Date(givenDate.toDateString() + 107 ' ' + givenDate.toLocaleTimeString()).toString(); 108 addTestCase(); 109 } 110 });