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.

     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/. */
     8 /**
     9    File Name:          15.9.5.5.js
    10    ECMA Section: 15.9.5.5 Date.prototype.toLocaleString()
    11    Description:
    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
    26 */
    28 var SECTION = "15.9.5.5";
    29 var VERSION = "ECMA_3"; 
    30 var TITLE   = "Date.prototype.toLocaleString()"; 
    32 var status = '';
    33 var actual = ''; 
    34 var expect = '';
    37 startTest();
    38 writeHeaderToLog( SECTION + " "+ TITLE);
    40 // first, some generic tests -
    42 status = "typeof (now.toLocaleString())"; 
    43 actual =   typeof (now.toLocaleString());
    44 expect = "string";
    45 addTestCase();
    47 status = "Date.prototype.toLocaleString.length";  
    48 actual =  Date.prototype.toLocaleString.length;
    49 expect =  0;  
    50 addTestCase();
    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;
    55 expect = true;
    56 addTestCase();
    60 // 1970
    61 addDateTestCase(0);
    62 addDateTestCase(TZ_ADJUST);  
    65 // 1900
    66 addDateTestCase(TIME_1900);
    67 addDateTestCase(TIME_1900 -TZ_ADJUST);
    70 // 2000
    71 addDateTestCase(TIME_2000);
    72 addDateTestCase(TIME_2000 -TZ_ADJUST);
    75 // 29 Feb 2000
    76 addDateTestCase(UTC_29_FEB_2000);
    77 addDateTestCase(UTC_29_FEB_2000 - 1000);   
    78 addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
    81 // 2005
    82 addDateTestCase(UTC_1_JAN_2005);
    83 addDateTestCase(UTC_1_JAN_2005 - 1000);
    84 addDateTestCase(UTC_1_JAN_2005-TZ_ADJUST);
    88 //-----------------------------------------------------------------------------------------------------
    89 test();
    90 //-----------------------------------------------------------------------------------------------------
    93 function addTestCase()
    94 {
    95   AddTestCase(
    96     status,
    97     expect,
    98     actual);
    99 }
   102 function addDateTestCase(date_given_in_milliseconds)
   103 {
   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;
   109   addTestCase();
   110 }

mercurial