js/src/tests/ecma/Date/15.9.5.2-1.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:6ecabd9b4aee
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
7 /**
8 File Name: 15.9.5.2.js
9 ECMA Section: 15.9.5.2 Date.prototype.toString
10 Description:
11 This function returns a string value. The contents of the string are
12 implementation dependent, but are intended to represent the Date in a
13 convenient, human-readable form in the current time zone.
14
15 The toString function is not generic; it generates a runtime error if its
16 this value is not a Date object. Therefore it cannot be transferred to
17 other kinds of objects for use as a method.
18
19 Author: christine@netscape.com
20 Date: 12 november 1997
21 */
22
23 var SECTION = "15.9.5.2";
24 var VERSION = "ECMA_1";
25 startTest();
26 var TITLE = "Date.prototype.toString";
27
28 writeHeaderToLog( SECTION + " "+ TITLE);
29
30 new TestCase( SECTION,
31 "Date.prototype.toString.length",
32 0,
33 Date.prototype.toString.length );
34
35 var now = new Date();
36
37 // can't test the content of the string, but can verify that the string is
38 // parsable by Date.parse
39
40 new TestCase( SECTION,
41 "Math.abs(Date.parse(now.toString()) - now.valueOf()) < 1000",
42 true,
43 Math.abs(Date.parse(now.toString()) - now.valueOf()) < 1000 );
44
45 new TestCase( SECTION,
46 "typeof now.toString()",
47 "string",
48 typeof now.toString() );
49 // 1970
50
51 new TestCase( SECTION,
52 "Date.parse( (new Date(0)).toString() )",
53 0,
54 Date.parse( (new Date(0)).toString() ) );
55
56 new TestCase( SECTION,
57 "Date.parse( (new Date("+TZ_ADJUST+")).toString() )",
58 TZ_ADJUST,
59 Date.parse( (new Date(TZ_ADJUST)).toString() ) );
60
61 // 1900
62 new TestCase( SECTION,
63 "Date.parse( (new Date("+TIME_1900+")).toString() )",
64 TIME_1900,
65 Date.parse( (new Date(TIME_1900)).toString() ) );
66
67 new TestCase( SECTION,
68 "Date.parse( (new Date("+TIME_1900 -TZ_ADJUST+")).toString() )",
69 TIME_1900 -TZ_ADJUST,
70 Date.parse( (new Date(TIME_1900 -TZ_ADJUST)).toString() ) );
71
72 // 2000
73 new TestCase( SECTION,
74 "Date.parse( (new Date("+TIME_2000+")).toString() )",
75 TIME_2000,
76 Date.parse( (new Date(TIME_2000)).toString() ) );
77
78 new TestCase( SECTION,
79 "Date.parse( (new Date("+TIME_2000 -TZ_ADJUST+")).toString() )",
80 TIME_2000 -TZ_ADJUST,
81 Date.parse( (new Date(TIME_2000 -TZ_ADJUST)).toString() ) );
82
83 // 29 Feb 2000
84
85 new TestCase( SECTION,
86 "Date.parse( (new Date("+UTC_FEB_29_2000+")).toString() )",
87 UTC_FEB_29_2000,
88 Date.parse( (new Date(UTC_FEB_29_2000)).toString() ) );
89
90 new TestCase( SECTION,
91 "Date.parse( (new Date("+(UTC_FEB_29_2000-1000)+")).toString() )",
92 UTC_FEB_29_2000-1000,
93 Date.parse( (new Date(UTC_FEB_29_2000-1000)).toString() ) );
94
95
96 new TestCase( SECTION,
97 "Date.parse( (new Date("+(UTC_FEB_29_2000-TZ_ADJUST)+")).toString() )",
98 UTC_FEB_29_2000-TZ_ADJUST,
99 Date.parse( (new Date(UTC_FEB_29_2000-TZ_ADJUST)).toString() ) );
100 // 2O05
101
102 new TestCase( SECTION,
103 "Date.parse( (new Date("+UTC_JAN_1_2005+")).toString() )",
104 UTC_JAN_1_2005,
105 Date.parse( (new Date(UTC_JAN_1_2005)).toString() ) );
106
107 new TestCase( SECTION,
108 "Date.parse( (new Date("+(UTC_JAN_1_2005-1000)+")).toString() )",
109 UTC_JAN_1_2005-1000,
110 Date.parse( (new Date(UTC_JAN_1_2005-1000)).toString() ) );
111
112 new TestCase( SECTION,
113 "Date.parse( (new Date("+(UTC_JAN_1_2005-TZ_ADJUST)+")).toString() )",
114 UTC_JAN_1_2005-TZ_ADJUST,
115 Date.parse( (new Date(UTC_JAN_1_2005-TZ_ADJUST)).toString() ) );
116
117 test();

mercurial