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/
5 *
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.
10 *
11 * The Original Code is Mozilla Communicator client code, released March
12 * 31, 1998.
13 *
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
17 * Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 */
22/**
23    File Name:          15.9.5.3.js
24    ECMA Section: 15.9.5.3 Date.prototype.toDateString()
25    Description:
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
31
32    The toDateString 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.
35
36    Author:  pschwartau@netscape.com
37    Date:      14 november 2000  (adapted from ecma/Date/15.9.5.2.js)
38*/
39
40   var SECTION = "15.9.5.3";
41   var VERSION = "ECMA_3";
42   var TITLE   = "Date.prototype.toDateString()";
43
44   var status = '';
45   var actual = '';
46   var expect = '';
47
48
49   startTest();
50   writeHeaderToLog( SECTION + " "+ TITLE);
51
52
53//-----------------------------------------------------------------------------------------------------
54   var testcases = new Array();
55//-----------------------------------------------------------------------------------------------------
56
57
58   // first, some generic tests -
59
60   status = "typeof (now.toDateString())";
61   actual =   typeof (now.toDateString());
62   expect = "string";
63   addTestCase();
64
65   status = "Date.prototype.toDateString.length";
66   actual =  Date.prototype.toDateString.length;
67   expect =  0;
68   addTestCase();
69
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.toDateString()) - (midnight(now)).valueOf()) == 0";
73   actual =   (Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0;
74   expect = true;
75   addTestCase();
76
77
78
79   // 1970
80   addDateTestCase(0);
81   addDateTestCase(TZ_ADJUST);
82
83
84   // 1900
85   addDateTestCase(TIME_1900);
86   addDateTestCase(TIME_1900 - TZ_ADJUST);
87
88
89   // 2000
90   addDateTestCase(TIME_2000);
91   addDateTestCase(TIME_2000 - TZ_ADJUST);
92
93
94   // 29 Feb 2000
95   addDateTestCase(UTC_29_FEB_2000);
96   addDateTestCase(UTC_29_FEB_2000 - 1000);
97   addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
98
99
100   // 2005
101   addDateTestCase(UTC_1_JAN_2005);
102   addDateTestCase(UTC_1_JAN_2005 - 1000);
103   addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST);
104
105
106
107//-----------------------------------------------------------------------------------------------------
108   test();
109//-----------------------------------------------------------------------------------------------------
110
111
112function addTestCase()
113{
114  testcases[tc++] = new TestCase( SECTION, status, expect, actual);
115}
116
117
118function addDateTestCase(date_given_in_milliseconds)
119{
120  var givenDate = new Date(date_given_in_milliseconds);
121
122  status = 'Date.parse('   +   givenDate   +   ').toDateString())';
123  actual =  Date.parse(givenDate.toDateString());
124  expect = Date.parse(midnight(givenDate));
125  addTestCase();
126}
127
128
129function midnight(givenDate)
130{
131  // midnight on the given date -
132  return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate());
133}
134
135
136function test()
137{
138  for ( tc=0; tc < testcases.length; tc++ )
139  {
140    testcases[tc].passed = writeTestCaseResult(
141                                               testcases[tc].expect,
142                                               testcases[tc].actual,
143                                               testcases[tc].description  +  " = "  +  testcases[tc].actual );
144
145    testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
146  }
147  stopTest();
148  return (testcases);
149}