js/src/tests/ecma_3/Date/15.9.5.6.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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 File Name: 15.9.5.6.js
michael@0 9 ECMA Section: 15.9.5.6 Date.prototype.toLocaleDateString()
michael@0 10 Description:
michael@0 11 This function returns a string value. The contents of the string are
michael@0 12 implementation dependent, but are intended to represent the "date"
michael@0 13 portion of the Date in the current time zone in a convenient,
michael@0 14 human-readable form. We can't test the content of the string,
michael@0 15 but can verify that the string is parsable by Date.parse
michael@0 16
michael@0 17 The toLocaleDateString function is not generic; it generates a runtime error
michael@0 18 if its 'this' value is not a Date object. Therefore it cannot be transferred
michael@0 19 to other kinds of objects for use as a method.
michael@0 20
michael@0 21 Note: This test isn't supposed to work with a non-English locale per spec.
michael@0 22
michael@0 23 Author: pschwartau@netscape.com
michael@0 24 Date: 14 november 2000
michael@0 25 */
michael@0 26
michael@0 27 var SECTION = "15.9.5.6";
michael@0 28 var VERSION = "ECMA_3";
michael@0 29 var TITLE = "Date.prototype.toLocaleDateString()";
michael@0 30
michael@0 31 var status = '';
michael@0 32 var actual = '';
michael@0 33 var expect = '';
michael@0 34
michael@0 35
michael@0 36 startTest();
michael@0 37 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 38
michael@0 39 // first, some generic tests -
michael@0 40
michael@0 41 status = "typeof (now.toLocaleDateString())";
michael@0 42 actual = typeof (now.toLocaleDateString());
michael@0 43 expect = "string";
michael@0 44 addTestCase();
michael@0 45
michael@0 46 status = "Date.prototype.toLocaleDateString.length";
michael@0 47 actual = Date.prototype.toLocaleDateString.length;
michael@0 48 expect = 0;
michael@0 49 addTestCase();
michael@0 50
michael@0 51 /* Date.parse is accurate to the second; valueOf() to the millisecond.
michael@0 52 Here we expect them to coincide, as we expect a time of exactly midnight - */
michael@0 53 status = "(Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0";
michael@0 54 actual = (Date.parse(now.toLocaleDateString()) - (midnight(now)).valueOf()) == 0;
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 new TestCase(
michael@0 96 "unknown-test-name",
michael@0 97 status,
michael@0 98 expect,
michael@0 99 actual);
michael@0 100 }
michael@0 101
michael@0 102
michael@0 103 function addDateTestCase(date_given_in_milliseconds)
michael@0 104 {
michael@0 105 var givenDate = new Date(date_given_in_milliseconds);
michael@0 106
michael@0 107 status = 'Date.parse(' + givenDate + ').toLocaleDateString())';
michael@0 108 actual = Date.parse(givenDate.toLocaleDateString());
michael@0 109 expect = Date.parse(midnight(givenDate));
michael@0 110 addTestCase();
michael@0 111 }
michael@0 112
michael@0 113
michael@0 114 function midnight(givenDate)
michael@0 115 {
michael@0 116 // midnight on the given date -
michael@0 117 return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate());
michael@0 118 }
michael@0 119

mercurial