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

mercurial