js/src/tests/ecma_3/Date/15.9.5.6.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:d64f36ac493b
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.6.js
9 ECMA Section: 15.9.5.6 Date.prototype.toLocaleDateString()
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"
13 portion of the Date in the current time zone in a convenient,
14 human-readable form. We can't test the content of the string,
15 but can verify that the string is parsable by Date.parse
16
17 The toLocaleDateString function is not generic; it generates a runtime error
18 if its 'this' value is not a Date object. Therefore it cannot be transferred
19 to other kinds of objects for use as a method.
20
21 Note: This test isn't supposed to work with a non-English locale per spec.
22
23 Author: pschwartau@netscape.com
24 Date: 14 november 2000
25 */
26
27 var SECTION = "15.9.5.6";
28 var VERSION = "ECMA_3";
29 var TITLE = "Date.prototype.toLocaleDateString()";
30
31 var status = '';
32 var actual = '';
33 var expect = '';
34
35
36 startTest();
37 writeHeaderToLog( SECTION + " "+ TITLE);
38
39 // first, some generic tests -
40
41 status = "typeof (now.toLocaleDateString())";
42 actual = typeof (now.toLocaleDateString());
43 expect = "string";
44 addTestCase();
45
46 status = "Date.prototype.toLocaleDateString.length";
47 actual = Date.prototype.toLocaleDateString.length;
48 expect = 0;
49 addTestCase();
50
51 /* Date.parse is accurate to the second; valueOf() to the millisecond.
52 Here we expect them to coincide, as we expect a time of exactly midnight - */
53 status = "(Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0";
54 actual = (Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0;
55 expect = true;
56 addTestCase();
57
58
59
60 // 1970
61 addDateTestCase(0);
62 addDateTestCase(TZ_ADJUST);
63
64
65 // 1900
66 addDateTestCase(TIME_1900);
67 addDateTestCase(TIME_1900 - TZ_ADJUST);
68
69
70 // 2000
71 addDateTestCase(TIME_2000);
72 addDateTestCase(TIME_2000 - TZ_ADJUST);
73
74
75 // 29 Feb 2000
76 addDateTestCase(UTC_29_FEB_2000);
77 addDateTestCase(UTC_29_FEB_2000 - 1000);
78 addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
79
80
81 // 2005
82 addDateTestCase(UTC_1_JAN_2005);
83 addDateTestCase(UTC_1_JAN_2005 - 1000);
84 addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST);
85
86
87
88 //-----------------------------------------------------------------------------------------------------
89 test();
90 //-----------------------------------------------------------------------------------------------------
91
92
93 function addTestCase()
94 {
95 new TestCase(
96 "unknown-test-name",
97 status,
98 expect,
99 actual);
100 }
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 + ').toLocaleDateString())';
108 actual = Date.parse(givenDate.toLocaleDateString());
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

mercurial