Debian Codegraph @

rhino/testsrc/tests/ecma_3/Date/15.9.5.6.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 var gTestfile = '15.9.5.6.js';
7
8 /**
9 File Name: 15.9.5.6.js
10 ECMA Section: 15.9.5.6 Date.prototype.toLocaleDateString()
11 Description:
12 This function returns a string value. The contents of the string are
13 implementation dependent, but are intended to represent the "date"
14 portion of the Date in the current time zone in a convenient,
15 human-readable form. We can't test the content of the string,
16 but can verify that the string is parsable by Date.parse
17
18 The toLocaleDateString function is not generic; it generates a runtime error
19 if its 'this' value is not a Date object. Therefore it cannot be transferred
20 to other kinds of objects for use as a method.
21
22 Note: This test isn't supposed to work with a non-English locale per spec.
23
24 Author: [email protected]
25 Date: 14 november 2000
26 */
27
28 var SECTION = "15.9.5.6";
29 var VERSION = "ECMA_3";
30 var TITLE = "Date.prototype.toLocaleDateString()";
31
32 var status = '';
33 var actual = '';
34 var expect = '';
35
36
37 startTest();
38 writeHeaderToLog( SECTION + " "+ TITLE);
39
40 // first, some generic tests -
41
42 status = "typeof (now.toLocaleDateString())";
43 actual = typeof (now.toLocaleDateString());
44 expect = "string";
45 addTestCase();
46
47 status = "Date.prototype.toLocaleDateString.length";
48 actual = Date.prototype.toLocaleDateString.length;
49 expect = 0;
50 addTestCase();
51
52 /* Date.parse is accurate to the second; valueOf() to the millisecond.
53 Here we expect them to coincide, as we expect a time of exactly midnight - */
54 status = "(Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0";
55 actual = (Date.parse(now.toLocaleDateString()) - (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 gTestfile,
98 status,
99 expect,
100 actual);
101 }
102
103
104 function addDateTestCase(date_given_in_milliseconds)
105 {
106 var givenDate = new Date(date_given_in_milliseconds);
107
108 status = 'Date.parse(' + givenDate + ').toLocaleDateString())';
109 actual = Date.parse(givenDate.toLocaleDateString());
110 expect = Date.parse(midnight(givenDate));
111 addTestCase();
112 }
113
114
115 function midnight(givenDate)
116 {
117 // midnight on the given date -
118 return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate());
119 }
120