1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
23 File Name: 15.9.5.6.js
24 ECMA Section: 15.9.5.6 Date.prototype.toLocaleDateString()
26 This function returns a string value. The contents of the string are
27 implementation dependent, but are intended to represent the "date"
28 portion of the Date in the current time zone in a convenient,
29 human-readable form. We can't test the content of the string,
30 but can verify that the string is parsable by Date.parse
32 The toLocaleDateString function is not generic; it generates a runtime error
33 if its 'this' value is not a Date object. Therefore it cannot be transferred
34 to other kinds of objects for use as a method.
36 Author: pschwartau@netscape.com
37 Date: 14 november 2000
40 var SECTION = "15.9.5.6";
41 var VERSION = "ECMA_3";
42 var TITLE = "Date.prototype.toLocaleDateString()";
50 writeHeaderToLog( SECTION + " "+ TITLE);
53 //-----------------------------------------------------------------------------------------------------
54 var testcases = new Array();
55 //-----------------------------------------------------------------------------------------------------
58 // first, some generic tests -
60 status = "typeof (now.toLocaleDateString())";
61 actual = typeof (now.toLocaleDateString());
65 status = "Date.prototype.toLocaleDateString.length";
66 actual = Date.prototype.toLocaleDateString.length;
70 /* Date.parse is accurate to the second; valueOf() to the millisecond.
71 Here we expect them to coincide, as we expect a time of exactly midnight - */
72 status = "(Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0";
73 actual = (Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0;
81 addDateTestCase(TZ_ADJUST);
85 addDateTestCase(TIME_1900);
86 addDateTestCase(TIME_1900 - TZ_ADJUST);
90 addDateTestCase(TIME_2000);
91 addDateTestCase(TIME_2000 - TZ_ADJUST);
95 addDateTestCase(UTC_29_FEB_2000);
96 addDateTestCase(UTC_29_FEB_2000 - 1000);
97 addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
101 addDateTestCase(UTC_1_JAN_2005);
102 addDateTestCase(UTC_1_JAN_2005 - 1000);
103 addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST);
107 //-----------------------------------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------------------------------
112 function addTestCase()
114 testcases[tc++] = new TestCase( SECTION, status, expect, actual);
118 function addDateTestCase(date_given_in_milliseconds)
120 var givenDate = new Date(date_given_in_milliseconds);
122 status = 'Date.parse(' + givenDate + ').toLocaleDateString())';
123 actual = Date.parse(givenDate.toLocaleDateString());
124 expect = Date.parse(midnight(givenDate));
129 function midnight(givenDate)
131 // midnight on the given date -
132 return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate());
138 for ( tc=0; tc < testcases.length; tc++ )
140 testcases[tc].passed = writeTestCaseResult(
141 testcases[tc].expect,
142 testcases[tc].actual,
143 testcases[tc].description + " = " + testcases[tc].actual );
145 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";