Debian Codegraph @

rhino/testsrc/tests/ecma_3/Date/15.9.5.3.js

raw symbols SCIP
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 File Name: 15.9.5.3.js
8 ECMA Section: 15.9.5.3 Date.prototype.toDateString()
9 Description:
10 This function returns a string value. The contents of the string are
11 implementation dependent, but are intended to represent the "date"
12 portion of the Date in the current time zone in a convenient,
13 human-readable form. We can't test the content of the string,
14 but can verify that the string is parsable by Date.parse
15
16 The toDateString function is not generic; it generates a runtime error
17 if its 'this' value is not a Date object. Therefore it cannot be transferred
18 to other kinds of objects for use as a method.
19
20 Author: [email protected]
21 Date: 14 november 2000 (adapted from ecma/Date/15.9.5.2.js)
22 */
23
24 var gTestfile = '15.9.5.3.js';
25 var SECTION = "15.9.5.3";
26 var VERSION = "ECMA_3";
27 var TITLE = "Date.prototype.toDateString()";
28
29 var status = '';
30 var actual = '';
31 var expect = '';
32
33
34 startTest();
35 writeHeaderToLog( SECTION + " "+ TITLE);
36
37 // first, some generic tests -
38
39 status = "typeof (now.toDateString())";
40 actual = typeof (now.toDateString());
41 expect = "string";
42 addTestCase();
43
44 status = "Date.prototype.toDateString.length";
45 actual = Date.prototype.toDateString.length;
46 expect = 0;
47 addTestCase();
48
49 /*
50 * Date.parse is accurate to the second; valueOf() to the millisecond.
51 * Here we expect them to coincide, as we expect a time of exactly
52 * midnight -
53 */
54 status = "(Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0";
55 actual = (Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0;
56 expect = true;
57 addTestCase();
58
59
60
61 // 1970
62 addDateTestCase(0);
63 addDateTestCase(TZ_ADJUST);
64
65
66 // 1900
67 addDateTestCase(TIME_1900);
68 addDateTestCase(TIME_1900 - TZ_ADJUST);
69
70
71 // 2000
72 addDateTestCase(TIME_2000);
73 addDateTestCase(TIME_2000 - TZ_ADJUST);
74
75
76 // 29 Feb 2000
77 addDateTestCase(UTC_29_FEB_2000);
78 addDateTestCase(UTC_29_FEB_2000 - 1000);
79 addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
80
81
82 // 2005
83 addDateTestCase(UTC_1_JAN_2005);
84 addDateTestCase(UTC_1_JAN_2005 - 1000);
85 addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST);
86
87
88
89 //-----------------------------------------------------------------------------
90 test();
91 //-----------------------------------------------------------------------------
92
93
94 function addTestCase()
95 {
96 new TestCase(
97 SECTION,
98 status,
99 expect,
100 actual);
101 }
102
103 function addDateTestCase(date_given_in_milliseconds)
104 {
105 var givenDate = new Date(date_given_in_milliseconds);
106
107 status = 'Date.parse(' + givenDate + ').toDateString())';
108 actual = Date.parse(givenDate.toDateString());
109 expect = Date.parse(midnight(givenDate));
110 addTestCase();
111 }
112
113
114 function midnight(givenDate)
115 {
116 // midnight on the given date -
117 return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate());
118 }
119