1
// |reftest| random-if(xulRuntime.OS=="Linux")
2
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10
ECMA Section: 15.9.5.5 Date.prototype.toLocaleString()
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
18
The toLocaleString 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.
22
Note: This test isn't supposed to work with a non-English locale per spec.
24
Author: pschwartau@netscape.com
25
Date: 14 november 2000
28
var SECTION = "15.9.5.5";
29
var VERSION = "ECMA_3";
30
var TITLE = "Date.prototype.toLocaleString()";
38
writeHeaderToLog( SECTION + " "+ TITLE);
40
// first, some generic tests -
42
status = "typeof (now.toLocaleString())";
43
actual = typeof (now.toLocaleString());
47
status = "Date.prototype.toLocaleString.length";
48
actual = Date.prototype.toLocaleString.length;
52
// Date.parse is accurate to the second; valueOf() to the millisecond -
53
status = "Math.abs(Date.parse(now.toLocaleString()) - now.valueOf()) < 1000";
54
actual = Math.abs(Date.parse(now.toLocaleString()) - now.valueOf()) < 1000;
62
addDateTestCase(TZ_ADJUST);
66
addDateTestCase(TIME_1900);
67
addDateTestCase(TIME_1900 -TZ_ADJUST);
71
addDateTestCase(TIME_2000);
72
addDateTestCase(TIME_2000 -TZ_ADJUST);
76
addDateTestCase(UTC_29_FEB_2000);
77
addDateTestCase(UTC_29_FEB_2000 - 1000);
78
addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
82
addDateTestCase(UTC_1_JAN_2005);
83
addDateTestCase(UTC_1_JAN_2005 - 1000);
84
addDateTestCase(UTC_1_JAN_2005-TZ_ADJUST);
88
//-----------------------------------------------------------------------------------------------------
90
//-----------------------------------------------------------------------------------------------------
93
function addTestCase()
102
function addDateTestCase(date_given_in_milliseconds)
104
var givenDate = new Date(date_given_in_milliseconds);
106
status = 'Date.parse(' + givenDate + ').toLocaleString())';
107
actual = Date.parse(givenDate.toLocaleString());
108
expect = date_given_in_milliseconds;