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.

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

mercurial