js/src/tests/ecma_3/Date/15.9.5.5.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // |reftest| random-if(xulRuntime.OS=="Linux")
michael@0 2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7
michael@0 8 /**
michael@0 9 File Name: 15.9.5.5.js
michael@0 10 ECMA Section: 15.9.5.5 Date.prototype.toLocaleString()
michael@0 11 Description:
michael@0 12 This function returns a string value. The contents of the string are
michael@0 13 implementation dependent, but are intended to represent the "date"
michael@0 14 portion of the Date in the current time zone in a convenient,
michael@0 15 human-readable form. We can't test the content of the string,
michael@0 16 but can verify that the string is parsable by Date.parse
michael@0 17
michael@0 18 The toLocaleString function is not generic; it generates a runtime error
michael@0 19 if its 'this' value is not a Date object. Therefore it cannot be transferred
michael@0 20 to other kinds of objects for use as a method.
michael@0 21
michael@0 22 Note: This test isn't supposed to work with a non-English locale per spec.
michael@0 23
michael@0 24 Author: pschwartau@netscape.com
michael@0 25 Date: 14 november 2000
michael@0 26 */
michael@0 27
michael@0 28 var SECTION = "15.9.5.5";
michael@0 29 var VERSION = "ECMA_3";
michael@0 30 var TITLE = "Date.prototype.toLocaleString()";
michael@0 31
michael@0 32 var status = '';
michael@0 33 var actual = '';
michael@0 34 var expect = '';
michael@0 35
michael@0 36
michael@0 37 startTest();
michael@0 38 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 39
michael@0 40 // first, some generic tests -
michael@0 41
michael@0 42 status = "typeof (now.toLocaleString())";
michael@0 43 actual = typeof (now.toLocaleString());
michael@0 44 expect = "string";
michael@0 45 addTestCase();
michael@0 46
michael@0 47 status = "Date.prototype.toLocaleString.length";
michael@0 48 actual = Date.prototype.toLocaleString.length;
michael@0 49 expect = 0;
michael@0 50 addTestCase();
michael@0 51
michael@0 52 // Date.parse is accurate to the second; valueOf() to the millisecond -
michael@0 53 status = "Math.abs(Date.parse(now.toLocaleString()) - now.valueOf()) < 1000";
michael@0 54 actual = Math.abs(Date.parse(now.toLocaleString()) - now.valueOf()) < 1000;
michael@0 55 expect = true;
michael@0 56 addTestCase();
michael@0 57
michael@0 58
michael@0 59
michael@0 60 // 1970
michael@0 61 addDateTestCase(0);
michael@0 62 addDateTestCase(TZ_ADJUST);
michael@0 63
michael@0 64
michael@0 65 // 1900
michael@0 66 addDateTestCase(TIME_1900);
michael@0 67 addDateTestCase(TIME_1900 -TZ_ADJUST);
michael@0 68
michael@0 69
michael@0 70 // 2000
michael@0 71 addDateTestCase(TIME_2000);
michael@0 72 addDateTestCase(TIME_2000 -TZ_ADJUST);
michael@0 73
michael@0 74
michael@0 75 // 29 Feb 2000
michael@0 76 addDateTestCase(UTC_29_FEB_2000);
michael@0 77 addDateTestCase(UTC_29_FEB_2000 - 1000);
michael@0 78 addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
michael@0 79
michael@0 80
michael@0 81 // 2005
michael@0 82 addDateTestCase(UTC_1_JAN_2005);
michael@0 83 addDateTestCase(UTC_1_JAN_2005 - 1000);
michael@0 84 addDateTestCase(UTC_1_JAN_2005-TZ_ADJUST);
michael@0 85
michael@0 86
michael@0 87
michael@0 88 //-----------------------------------------------------------------------------------------------------
michael@0 89 test();
michael@0 90 //-----------------------------------------------------------------------------------------------------
michael@0 91
michael@0 92
michael@0 93 function addTestCase()
michael@0 94 {
michael@0 95 AddTestCase(
michael@0 96 status,
michael@0 97 expect,
michael@0 98 actual);
michael@0 99 }
michael@0 100
michael@0 101
michael@0 102 function addDateTestCase(date_given_in_milliseconds)
michael@0 103 {
michael@0 104 var givenDate = new Date(date_given_in_milliseconds);
michael@0 105
michael@0 106 status = 'Date.parse(' + givenDate + ').toLocaleString())';
michael@0 107 actual = Date.parse(givenDate.toLocaleString());
michael@0 108 expect = date_given_in_milliseconds;
michael@0 109 addTestCase();
michael@0 110 }
michael@0 111

mercurial