]>
Commit | Line | Data |
---|---|---|
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.2.js | |
24 | ECMA Section: 15.9.5.2 Date.prototype.toString | |
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 in a | |
28 | convenient, human-readable form in the current time zone. | |
29 | ||
30 | The toString function is not generic; it generates a runtime error if its | |
31 | this value is not a Date object. Therefore it cannot be transferred to | |
32 | other kinds of objects for use as a method. | |
33 | ||
34 | Author: christine@netscape.com | |
35 | Date: 12 november 1997 | |
36 | */ | |
37 | ||
38 | var SECTION = "15.9.5.2"; | |
39 | var VERSION = "ECMA_1"; | |
40 | startTest(); | |
41 | var TITLE = "Date.prototype.toString"; | |
42 | ||
43 | writeHeaderToLog( SECTION + " "+ TITLE); | |
44 | ||
45 | var testcases = new Array(); | |
46 | ||
47 | testcases[tc++] = new TestCase( SECTION, | |
48 | "Date.prototype.toString.length", | |
49 | 0, | |
50 | Date.prototype.toString.length ); | |
51 | ||
52 | var now = new Date(); | |
53 | ||
54 | // can't test the content of the string, but can verify that the string is | |
55 | // parsable by Date.parse | |
56 | ||
57 | testcases[tc++] = new TestCase( SECTION, | |
58 | "Math.abs(Date.parse(now.toString()) - now.valueOf()) < 1000", | |
59 | true, | |
60 | Math.abs(Date.parse(now.toString()) - now.valueOf()) < 1000 ); | |
61 | ||
62 | testcases[tc++] = new TestCase( SECTION, | |
63 | "typeof now.toString()", | |
64 | "string", | |
65 | typeof now.toString() ); | |
66 | // 1970 | |
67 | ||
68 | TZ_ADJUST = TZ_DIFF * msPerHour; | |
69 | ||
70 | testcases[tc++] = new TestCase( SECTION, | |
71 | "Date.parse( (new Date(0)).toString() )", | |
72 | 0, | |
73 | Date.parse( (new Date(0)).toString() ) ) | |
74 | ||
75 | testcases[tc++] = new TestCase( SECTION, | |
76 | "Date.parse( (new Date("+TZ_ADJUST+")).toString() )", | |
77 | TZ_ADJUST, | |
78 | Date.parse( (new Date(TZ_ADJUST)).toString() ) ) | |
79 | ||
80 | // 1900 | |
81 | testcases[tc++] = new TestCase( SECTION, | |
82 | "Date.parse( (new Date("+TIME_1900+")).toString() )", | |
83 | TIME_1900, | |
84 | Date.parse( (new Date(TIME_1900)).toString() ) ) | |
85 | ||
86 | testcases[tc++] = new TestCase( SECTION, | |
87 | "Date.parse( (new Date("+TIME_1900 -TZ_ADJUST+")).toString() )", | |
88 | TIME_1900 -TZ_ADJUST, | |
89 | Date.parse( (new Date(TIME_1900 -TZ_ADJUST)).toString() ) ) | |
90 | ||
91 | // 2000 | |
92 | testcases[tc++] = new TestCase( SECTION, | |
93 | "Date.parse( (new Date("+TIME_2000+")).toString() )", | |
94 | TIME_2000, | |
95 | Date.parse( (new Date(TIME_2000)).toString() ) ) | |
96 | ||
97 | testcases[tc++] = new TestCase( SECTION, | |
98 | "Date.parse( (new Date("+TIME_2000 -TZ_ADJUST+")).toString() )", | |
99 | TIME_2000 -TZ_ADJUST, | |
100 | Date.parse( (new Date(TIME_2000 -TZ_ADJUST)).toString() ) ) | |
101 | ||
102 | // 29 Feb 2000 | |
103 | ||
104 | var UTC_29_FEB_2000 = TIME_2000 + 31*msPerDay + 28*msPerDay; | |
105 | testcases[tc++] = new TestCase( SECTION, | |
106 | "Date.parse( (new Date("+UTC_29_FEB_2000+")).toString() )", | |
107 | UTC_29_FEB_2000, | |
108 | Date.parse( (new Date(UTC_29_FEB_2000)).toString() ) ) | |
109 | ||
110 | testcases[tc++] = new TestCase( SECTION, | |
111 | "Date.parse( (new Date("+(UTC_29_FEB_2000-1000)+")).toString() )", | |
112 | UTC_29_FEB_2000-1000, | |
113 | Date.parse( (new Date(UTC_29_FEB_2000-1000)).toString() ) ) | |
114 | ||
115 | ||
116 | testcases[tc++] = new TestCase( SECTION, | |
117 | "Date.parse( (new Date("+(UTC_29_FEB_2000-TZ_ADJUST)+")).toString() )", | |
118 | UTC_29_FEB_2000-TZ_ADJUST, | |
119 | Date.parse( (new Date(UTC_29_FEB_2000-TZ_ADJUST)).toString() ) ) | |
120 | // 2O05 | |
121 | ||
122 | var UTC_1_JAN_2005 = TIME_2000 + TimeInYear(2000) + TimeInYear(2001) + | |
123 | TimeInYear(2002) + TimeInYear(2003) + TimeInYear(2004); | |
124 | testcases[tc++] = new TestCase( SECTION, | |
125 | "Date.parse( (new Date("+UTC_1_JAN_2005+")).toString() )", | |
126 | UTC_1_JAN_2005, | |
127 | Date.parse( (new Date(UTC_1_JAN_2005)).toString() ) ) | |
128 | ||
129 | testcases[tc++] = new TestCase( SECTION, | |
130 | "Date.parse( (new Date("+(UTC_1_JAN_2005-1000)+")).toString() )", | |
131 | UTC_1_JAN_2005-1000, | |
132 | Date.parse( (new Date(UTC_1_JAN_2005-1000)).toString() ) ) | |
133 | ||
134 | testcases[tc++] = new TestCase( SECTION, | |
135 | "Date.parse( (new Date("+(UTC_1_JAN_2005-TZ_ADJUST)+")).toString() )", | |
136 | UTC_1_JAN_2005-TZ_ADJUST, | |
137 | Date.parse( (new Date(UTC_1_JAN_2005-TZ_ADJUST)).toString() ) ) | |
138 | ||
139 | test(); | |
140 | function test() { | |
141 | for ( tc=0; tc < testcases.length; tc++ ) { | |
142 | testcases[tc].passed = writeTestCaseResult( | |
143 | testcases[tc].expect, | |
144 | testcases[tc].actual, | |
145 | testcases[tc].description +" = "+ | |
146 | testcases[tc].actual ); | |
147 | ||
148 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
149 | } | |
150 | stopTest(); | |
151 | return ( testcases ); | |
152 | } |