1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/Date/15.9.5.6.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,119 @@ 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 +/** 1.11 + File Name: 15.9.5.6.js 1.12 + ECMA Section: 15.9.5.6 Date.prototype.toLocaleDateString() 1.13 + Description: 1.14 + This function returns a string value. The contents of the string are 1.15 + implementation dependent, but are intended to represent the "date" 1.16 + portion of the Date in the current time zone in a convenient, 1.17 + human-readable form. We can't test the content of the string, 1.18 + but can verify that the string is parsable by Date.parse 1.19 + 1.20 + The toLocaleDateString function is not generic; it generates a runtime error 1.21 + if its 'this' value is not a Date object. Therefore it cannot be transferred 1.22 + to other kinds of objects for use as a method. 1.23 + 1.24 + Note: This test isn't supposed to work with a non-English locale per spec. 1.25 + 1.26 + Author: pschwartau@netscape.com 1.27 + Date: 14 november 2000 1.28 +*/ 1.29 + 1.30 +var SECTION = "15.9.5.6"; 1.31 +var VERSION = "ECMA_3"; 1.32 +var TITLE = "Date.prototype.toLocaleDateString()"; 1.33 + 1.34 +var status = ''; 1.35 +var actual = ''; 1.36 +var expect = ''; 1.37 + 1.38 + 1.39 +startTest(); 1.40 +writeHeaderToLog( SECTION + " "+ TITLE); 1.41 + 1.42 +// first, some generic tests - 1.43 + 1.44 +status = "typeof (now.toLocaleDateString())"; 1.45 +actual = typeof (now.toLocaleDateString()); 1.46 +expect = "string"; 1.47 +addTestCase(); 1.48 + 1.49 +status = "Date.prototype.toLocaleDateString.length"; 1.50 +actual = Date.prototype.toLocaleDateString.length; 1.51 +expect = 0; 1.52 +addTestCase(); 1.53 + 1.54 +/* Date.parse is accurate to the second; valueOf() to the millisecond. 1.55 + Here we expect them to coincide, as we expect a time of exactly midnight - */ 1.56 +status = "(Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0"; 1.57 +actual = (Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0; 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 + new TestCase( 1.99 + "unknown-test-name", 1.100 + status, 1.101 + expect, 1.102 + actual); 1.103 +} 1.104 + 1.105 + 1.106 +function addDateTestCase(date_given_in_milliseconds) 1.107 +{ 1.108 + var givenDate = new Date(date_given_in_milliseconds); 1.109 + 1.110 + status = 'Date.parse(' + givenDate + ').toLocaleDateString())'; 1.111 + actual = Date.parse(givenDate.toLocaleDateString()); 1.112 + expect = Date.parse(midnight(givenDate)); 1.113 + addTestCase(); 1.114 +} 1.115 + 1.116 + 1.117 +function midnight(givenDate) 1.118 +{ 1.119 + // midnight on the given date - 1.120 + return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate()); 1.121 +} 1.122 +