js/src/tests/ecma_3/Date/15.9.5.3.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_3/Date/15.9.5.3.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/**
    1.10 +   File Name:          15.9.5.3.js
    1.11 +   ECMA Section: 15.9.5.3 Date.prototype.toDateString()
    1.12 +   Description:
    1.13 +   This function returns a string value. The contents of the string are
    1.14 +   implementation dependent, but are intended to represent the "date"
    1.15 +   portion of the Date in the current time zone in a convenient,
    1.16 +   human-readable form.   We can't test the content of the string, 
    1.17 +   but can verify that the string is parsable by Date.parse
    1.18 +
    1.19 +   The toDateString function is not generic; it generates a runtime error
    1.20 +   if its 'this' value is not a Date object. Therefore it cannot be transferred
    1.21 +   to other kinds of objects for use as a method.
    1.22 +
    1.23 +   Author:  pschwartau@netscape.com                            
    1.24 +   Date:      14 november 2000  (adapted from ecma/Date/15.9.5.2.js)
    1.25 +*/
    1.26 +
    1.27 +var SECTION = "15.9.5.3";
    1.28 +var VERSION = "ECMA_3"; 
    1.29 +var TITLE   = "Date.prototype.toDateString()"; 
    1.30 +  
    1.31 +var status = '';
    1.32 +var actual = ''; 
    1.33 +var expect = '';
    1.34 +
    1.35 +
    1.36 +startTest();
    1.37 +writeHeaderToLog( SECTION + " "+ TITLE);
    1.38 +
    1.39 +// first, some generic tests -
    1.40 +
    1.41 +status = "typeof (now.toDateString())"; 
    1.42 +actual =   typeof (now.toDateString());
    1.43 +expect = "string";
    1.44 +addTestCase();
    1.45 +
    1.46 +status = "Date.prototype.toDateString.length";  
    1.47 +actual =  Date.prototype.toDateString.length;
    1.48 +expect =  0;  
    1.49 +addTestCase();
    1.50 +
    1.51 +/*
    1.52 + * Date.parse is accurate to the second; valueOf() to the millisecond.
    1.53 + * Here we expect them to coincide, as we expect a time of exactly
    1.54 + * midnight -
    1.55 + */
    1.56 +status = "(Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0";  
    1.57 +actual =   (Date.parse(now.toDateString()) - (midnight(now)).valueOf()) == 0;
    1.58 +expect = true;
    1.59 +addTestCase();
    1.60 +
    1.61 +
    1.62 +
    1.63 +// 1970
    1.64 +addDateTestCase(0);
    1.65 +addDateTestCase(TZ_ADJUST);  
    1.66 +
    1.67 +  
    1.68 +// 1900
    1.69 +addDateTestCase(TIME_1900);
    1.70 +addDateTestCase(TIME_1900 - TZ_ADJUST);
    1.71 +
    1.72 +  
    1.73 +// 2000
    1.74 +addDateTestCase(TIME_2000);
    1.75 +addDateTestCase(TIME_2000 - TZ_ADJUST);
    1.76 +
    1.77 +   
    1.78 +// 29 Feb 2000
    1.79 +addDateTestCase(UTC_29_FEB_2000);
    1.80 +addDateTestCase(UTC_29_FEB_2000 - 1000);   
    1.81 +addDateTestCase(UTC_29_FEB_2000 - TZ_ADJUST);
    1.82 +
    1.83 +
    1.84 +// 2005
    1.85 +addDateTestCase(UTC_1_JAN_2005);
    1.86 +addDateTestCase(UTC_1_JAN_2005 - 1000);
    1.87 +addDateTestCase(UTC_1_JAN_2005 - TZ_ADJUST);
    1.88 +  
    1.89 +
    1.90 +
    1.91 +//-----------------------------------------------------------------------------
    1.92 +test();
    1.93 +//-----------------------------------------------------------------------------
    1.94 +
    1.95 +
    1.96 +function addTestCase()
    1.97 +{
    1.98 +  new TestCase(
    1.99 +    SECTION,
   1.100 +    status,
   1.101 +    expect,
   1.102 +    actual);
   1.103 +}
   1.104 +
   1.105 +function addDateTestCase(date_given_in_milliseconds)
   1.106 +{
   1.107 +  var givenDate = new Date(date_given_in_milliseconds);
   1.108 +
   1.109 +  status = 'Date.parse('   +   givenDate   +   ').toDateString())';  
   1.110 +  actual =  Date.parse(givenDate.toDateString());
   1.111 +  expect = Date.parse(midnight(givenDate));
   1.112 +  addTestCase();
   1.113 +}
   1.114 +
   1.115 +
   1.116 +function midnight(givenDate)
   1.117 +{
   1.118 +  // midnight on the given date -
   1.119 +  return new Date(givenDate.getFullYear(), givenDate.getMonth(), givenDate.getDate());
   1.120 +}
   1.121 +

mercurial