Debian Codegraph @

js/src/tests/non262/Date/15.9.5.6.js

raw
1 /* -*- indent-tabs-mode: nil; js-indent-level: 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: [email protected]
24 Date: 14 november 2000
25 */
26
27 var SECTION = "15.9.5.6";
28 var TITLE = "Date.prototype.toLocaleDateString()";
29
30 var status = '';
31 var actual = '';
32 var expect = '';
33
34
35 writeHeaderToLog( SECTION + " "+ TITLE);
36
37 var now = new Date();
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('en-US')) - (midnight(now)).valueOf()) == 0";
54 actual = (Date.parse(now.toLocaleDateString('en-US')) - (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(UTC_01_JAN_1900);
67 addDateTestCase(UTC_01_JAN_1900 - TZ_ADJUST);
68
69
70 // 2000
71 addDateTestCase(UTC_01_JAN_2000);
72 addDateTestCase(UTC_01_JAN_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_01_JAN_2005);
83 addDateTestCase(UTC_01_JAN_2005 - 1000);
84 addDateTestCase(UTC_01_JAN_2005 - TZ_ADJUST);
85
86
87
88 //-----------------------------------------------------------------------------------------------------
89 test();
90 //-----------------------------------------------------------------------------------------------------
91
92
93 function addTestCase()
94 {
95 new TestCase(
96 status,
97 expect,
98 actual);
99 }
100
101
102 function addDateTestCase(date_given_in_milliseconds)
103 {
104 var givenDate = new Date(date_given_in_milliseconds);
105
106 status = 'Date.parse(' + givenDate + ').toLocaleDateString("en-US"))';
107 actual = Date.parse(givenDate.toLocaleDateString("en-US"));
108 expect = Date.parse(midnight(givenDate));
109 addTestCase();
110 }
111
112
113 function midnight(givenDate)
114 {
115 // midnight on the given date -
116 return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate());
117 }
118