Wed, 31 Dec 2014 06:09:35 +0100
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 | File Name: 15.9.5.3.js |
michael@0 | 8 | ECMA Section: 15.9.5.3 Date.prototype.toDateString() |
michael@0 | 9 | Description: |
michael@0 | 10 | This function returns a string value. The contents of the string are |
michael@0 | 11 | implementation dependent, but are intended to represent the "date" |
michael@0 | 12 | portion of the Date in the current time zone in a convenient, |
michael@0 | 13 | human-readable form. We can't test the content of the string, |
michael@0 | 14 | but can verify that the string is parsable by Date.parse |
michael@0 | 15 | |
michael@0 | 16 | The toDateString function is not generic; it generates a runtime error |
michael@0 | 17 | if its 'this' value is not a Date object. Therefore it cannot be transferred |
michael@0 | 18 | to other kinds of objects for use as a method. |
michael@0 | 19 | |
michael@0 | 20 | Author: pschwartau@netscape.com |
michael@0 | 21 | Date: 14 november 2000 (adapted from ecma/Date/15.9.5.2.js) |
michael@0 | 22 | */ |
michael@0 | 23 | |
michael@0 | 24 | var SECTION = "15.9.5.3"; |
michael@0 | 25 | var VERSION = "ECMA_3"; |
michael@0 | 26 | var TITLE = "Date.prototype.toDateString()"; |
michael@0 | 27 | |
michael@0 | 28 | var status = ''; |
michael@0 | 29 | var actual = ''; |
michael@0 | 30 | var expect = ''; |
michael@0 | 31 | |
michael@0 | 32 | |
michael@0 | 33 | startTest(); |
michael@0 | 34 | writeHeaderToLog( SECTION + " "+ TITLE); |
michael@0 | 35 | |
michael@0 | 36 | // first, some generic tests - |
michael@0 | 37 | |
michael@0 | 38 | status = "typeof (now.toDateString())"; |
michael@0 | 39 | actual = typeof (now.toDateString()); |
michael@0 | 40 | expect = "string"; |
michael@0 | 41 | addTestCase(); |
michael@0 | 42 | |
michael@0 | 43 | status = "Date.prototype.toDateString.length"; |
michael@0 | 44 | actual = Date.prototype.toDateString.length; |
michael@0 | 45 | expect = 0; |
michael@0 | 46 | addTestCase(); |
michael@0 | 47 | |
michael@0 | 48 | /* |
michael@0 | 49 | * Date.parse is accurate to the second; valueOf() to the millisecond. |
michael@0 | 50 | * Here we expect them to coincide, as we expect a time of exactly |
michael@0 | 51 | * midnight - |
michael@0 | 52 | */ |
michael@0 | 53 | status = "(Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0"; |
michael@0 | 54 | actual = (Date.parse(now.toDateString()) - (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 | SECTION, |
michael@0 | 97 | status, |
michael@0 | 98 | expect, |
michael@0 | 99 | actual); |
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 + ').toDateString())'; |
michael@0 | 107 | actual = Date.parse(givenDate.toDateString()); |
michael@0 | 108 | expect = Date.parse(midnight(givenDate)); |
michael@0 | 109 | addTestCase(); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | |
michael@0 | 113 | function midnight(givenDate) |
michael@0 | 114 | { |
michael@0 | 115 | // midnight on the given date - |
michael@0 | 116 | return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate()); |
michael@0 | 117 | } |
michael@0 | 118 |