1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/Date/15.9.5.5.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +// |reftest| random-if(xulRuntime.OS=="Linux") 1.5 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 +/** 1.12 + File Name: 15.9.5.5.js 1.13 + ECMA Section: 15.9.5.5 Date.prototype.toLocaleString() 1.14 + Description: 1.15 + This function returns a string value. The contents of the string are 1.16 + implementation dependent, but are intended to represent the "date" 1.17 + portion of the Date in the current time zone in a convenient, 1.18 + human-readable form. We can't test the content of the string, 1.19 + but can verify that the string is parsable by Date.parse 1.20 + 1.21 + The toLocaleString function is not generic; it generates a runtime error 1.22 + if its 'this' value is not a Date object. Therefore it cannot be transferred 1.23 + to other kinds of objects for use as a method. 1.24 + 1.25 + Note: This test isn't supposed to work with a non-English locale per spec. 1.26 + 1.27 + Author: pschwartau@netscape.com 1.28 + Date: 14 november 2000 1.29 +*/ 1.30 + 1.31 +var SECTION = "15.9.5.5"; 1.32 +var VERSION = "ECMA_3"; 1.33 +var TITLE = "Date.prototype.toLocaleString()"; 1.34 + 1.35 +var status = ''; 1.36 +var actual = ''; 1.37 +var expect = ''; 1.38 + 1.39 + 1.40 +startTest(); 1.41 +writeHeaderToLog( SECTION + " "+ TITLE); 1.42 + 1.43 +// first, some generic tests - 1.44 + 1.45 +status = "typeof (now.toLocaleString())"; 1.46 +actual = typeof (now.toLocaleString()); 1.47 +expect = "string"; 1.48 +addTestCase(); 1.49 + 1.50 +status = "Date.prototype.toLocaleString.length"; 1.51 +actual = Date.prototype.toLocaleString.length; 1.52 +expect = 0; 1.53 +addTestCase(); 1.54 + 1.55 +// Date.parse is accurate to the second; valueOf() to the millisecond - 1.56 +status = "Math.abs(Date.parse(now.toLocaleString()) - now.valueOf()) < 1000"; 1.57 +actual = Math.abs(Date.parse(now.toLocaleString()) - now.valueOf()) < 1000; 1.58 +expect = true; 1.59 +addTestCase(); 1.60 + 1.61 + 1.62 + 1.63 +// 1970 1.64 +addDateTestCase(0); 1.65 +addDateTestCase(TZ_ADJUST); 1.66 + 1.67 + 1.68 +// 1900 1.69 +addDateTestCase(TIME_1900); 1.70 +addDateTestCase(TIME_1900 -TZ_ADJUST); 1.71 + 1.72 + 1.73 +// 2000 1.74 +addDateTestCase(TIME_2000); 1.75 +addDateTestCase(TIME_2000 -TZ_ADJUST); 1.76 + 1.77 + 1.78 +// 29 Feb 2000 1.79 +addDateTestCase(UTC_29_FEB_2000); 1.80 +addDateTestCase(UTC_29_FEB_2000 - 1000); 1.81 +addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST); 1.82 + 1.83 + 1.84 +// 2005 1.85 +addDateTestCase(UTC_1_JAN_2005); 1.86 +addDateTestCase(UTC_1_JAN_2005 - 1000); 1.87 +addDateTestCase(UTC_1_JAN_2005-TZ_ADJUST); 1.88 + 1.89 + 1.90 + 1.91 +//----------------------------------------------------------------------------------------------------- 1.92 +test(); 1.93 +//----------------------------------------------------------------------------------------------------- 1.94 + 1.95 + 1.96 +function addTestCase() 1.97 +{ 1.98 + AddTestCase( 1.99 + status, 1.100 + expect, 1.101 + actual); 1.102 +} 1.103 + 1.104 + 1.105 +function addDateTestCase(date_given_in_milliseconds) 1.106 +{ 1.107 + var givenDate = new Date(date_given_in_milliseconds); 1.108 + 1.109 + status = 'Date.parse(' + givenDate + ').toLocaleString())'; 1.110 + actual = Date.parse(givenDate.toLocaleString()); 1.111 + expect = date_given_in_milliseconds; 1.112 + addTestCase(); 1.113 +} 1.114 +