Debian Codegraph @

rhino/testsrc/tests/ecma_3/Date/15.9.5.7.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.7.js
8 ECMA Section: 15.9.5.7 Date.prototype.toLocaleTimeString()
9 Description:
10 This function returns a string value. The contents of the string are
11 implementation dependent, but are intended to represent the "time"
12 portion of the Date in the current time zone in a convenient,
13 human-readable form. We test the content of the string by checking
14 that
15
16 new Date(d.toDateString() + " " + d.toLocaleTimeString()) == d
17
18 Author: [email protected]
19 Date: 14 november 2000
20 Revised: 07 january 2002 because of a change in JS Date format:
21 Revised: 21 November 2005 since the string comparison stuff is horked.
22 bclary
23
24 See http://bugzilla.mozilla.org/show_bug.cgi?id=118266 (SpiderMonkey)
25 See http://bugzilla.mozilla.org/show_bug.cgi?id=118636 (Rhino)
26 */
27 //-----------------------------------------------------------------------------
28 var gTestfile = '15.9.5.7.js';
29 var SECTION = "15.9.5.7";
30 var VERSION = "ECMA_3";
31 var TITLE = "Date.prototype.toLocaleTimeString()";
32
33 var status = '';
34 var actual = '';
35 var expect = '';
36 var givenDate;
37 var year = '';
38 var regexp = '';
39 var TimeString = '';
40 var reducedDateString = '';
41 var hopeThisIsLocaleTimeString = '';
42 var cnERR ='OOPS! FATAL ERROR: no regexp match in extractLocaleTimeString()';
43
44 startTest();
45 writeHeaderToLog( SECTION + " "+ TITLE);
46
47 // first, a couple generic tests -
48
49 status = "typeof (now.toLocaleTimeString())";
50 actual = typeof (now.toLocaleTimeString());
51 expect = "string";
52 addTestCase();
53
54 status = "Date.prototype.toLocaleTimeString.length";
55 actual = Date.prototype.toLocaleTimeString.length;
56 expect = 0;
57 addTestCase();
58
59 // 1970
60 addDateTestCase(0);
61 addDateTestCase(TZ_ADJUST);
62
63 // 1900
64 addDateTestCase(TIME_1900);
65 addDateTestCase(TIME_1900 - TZ_ADJUST);
66
67 // 2000
68 addDateTestCase(TIME_2000);
69 addDateTestCase(TIME_2000 - TZ_ADJUST);
70
71 // 29 Feb 2000
72 addDateTestCase(UTC_29_FEB_2000);
73 addDateTestCase(UTC_29_FEB_2000 - 1000);
74 addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
75
76 // Now
77 addDateTestCase( TIME_NOW);
78 addDateTestCase( TIME_NOW - TZ_ADJUST);
79
80 // 2005
81 addDateTestCase(UTC_1_JAN_2005);
82 addDateTestCase(UTC_1_JAN_2005 - 1000);
83 addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST);
84
85 test();
86
87 function addTestCase()
88 {
89 new TestCase(
90 SECTION,
91 status,
92 expect,
93 actual);
94 }
95
96
97 function addDateTestCase(date_given_in_milliseconds)
98 {
99 var s = 'new Date(' + date_given_in_milliseconds + ')';
100 givenDate = new Date(date_given_in_milliseconds);
101
102 status = 'd = ' + s +
103 '; d == new Date(d.toDateString() + " " + d.toLocaleTimeString())';
104 expect = givenDate.toString();
105 actual = new Date(givenDate.toDateString() +
106 ' ' + givenDate.toLocaleTimeString()).toString();
107 addTestCase();
108 }
109