js/src/tests/ecma/Date/15.9.4.2.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma/Date/15.9.4.2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,157 @@
     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 +/**
    1.11 +   File Name:          15.9.4.2.js
    1.12 +   ECMA Section:       15.9.4.2 Date.parse()
    1.13 +   Description:        The parse() function applies the to ToString() operator
    1.14 +   to its argument and interprets the resulting string as
    1.15 +   a date.  It returns a number, the UTC time value
    1.16 +   corresponding to the date.
    1.17 +
    1.18 +   The string may be interpreted as a local time, a UTC
    1.19 +   time, or a time in some other time zone, depending on
    1.20 +   the contents of the string.
    1.21 +
    1.22 +   (need to test strings containing stuff with the time
    1.23 +   zone specified, and verify that parse() returns the
    1.24 +   correct GMT time)
    1.25 +
    1.26 +   so for any Date object x, all of these things should
    1.27 +   be equal:
    1.28 +
    1.29 +   value                       tested in function:
    1.30 +   x.valueOf()                 test_value()
    1.31 +   Date.parse(x.toString())    test_tostring()
    1.32 +   Date.parse(x.toGMTString()) test_togmt()
    1.33 +
    1.34 +   Date.parse(x.toLocaleString()) is not required to
    1.35 +   produce the same number value as the preceding three
    1.36 +   expressions.  in general the value produced by
    1.37 +   Date.parse is implementation dependent when given any
    1.38 +   string value that could not be produced in that
    1.39 +   implementation by the toString or toGMTString method.
    1.40 +
    1.41 +   value                           tested in function:
    1.42 +   Date.parse( x.toLocaleString()) test_tolocale()
    1.43 +
    1.44 +   Author:             christine@netscape.com
    1.45 +   Date:               10 july 1997
    1.46 +
    1.47 +*/
    1.48 +
    1.49 +var VERSION = "ECMA_1";
    1.50 +startTest();
    1.51 +var SECTION = "15.9.4.2";
    1.52 +var TITLE   = "Date.parse()";
    1.53 +
    1.54 +var TIME        = 0;
    1.55 +var UTC_YEAR    = 1;
    1.56 +var UTC_MONTH   = 2;
    1.57 +var UTC_DATE    = 3;
    1.58 +var UTC_DAY     = 4;
    1.59 +var UTC_HOURS   = 5;
    1.60 +var UTC_MINUTES = 6;
    1.61 +var UTC_SECONDS = 7;
    1.62 +var UTC_MS      = 8;
    1.63 +
    1.64 +var YEAR        = 9;
    1.65 +var MONTH       = 10;
    1.66 +var DATE        = 11;
    1.67 +var DAY         = 12;
    1.68 +var HOURS       = 13;
    1.69 +var MINUTES     = 14;
    1.70 +var SECONDS     = 15;
    1.71 +var MS          = 16;
    1.72 +var TYPEOF  = "object";
    1.73 +
    1.74 +//  for TCMS, the gTestcases array must be global.
    1.75 +writeHeaderToLog("15.9.4.2 Date.parse()" );
    1.76 +
    1.77 +// Dates around 1970
    1.78 +
    1.79 +addNewTestCase( new Date(0),
    1.80 +		"new Date(0)",
    1.81 +		[0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] );
    1.82 +
    1.83 +addNewTestCase( new Date(-1),
    1.84 +		"new Date(-1)",
    1.85 +		[-1,1969,11,31,3,23,59,59,999,1969,11,31,3,15,59,59,999] );
    1.86 +addNewTestCase( new Date(28799999),
    1.87 +		"new Date(28799999)",
    1.88 +		[28799999,1970,0,1,4,7,59,59,999,1969,11,31,3,23,59,59,999] );
    1.89 +addNewTestCase( new Date(28800000),
    1.90 +		"new Date(28800000)",
    1.91 +		[28800000,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] );
    1.92 +
    1.93 +// Dates around 2000
    1.94 +
    1.95 +addNewTestCase( new Date(946684799999),
    1.96 +		"new Date(946684799999)",
    1.97 +		[946684799999,1999,11,31,5,23,59,59,999,1999,11,31,5,15,59,59,999] );
    1.98 +addNewTestCase( new Date(946713599999),
    1.99 +		"new Date(946713599999)",
   1.100 +		[946713599999,2000,0,1,6,7,59,59,999,1999,11,31,5,23,59,59,999] );
   1.101 +addNewTestCase( new Date(946684800000),
   1.102 +		"new Date(946684800000)",
   1.103 +		[946684800000,2000,0,1,6,0,0,0,0,1999,11,31,5, 16,0,0,0] );
   1.104 +addNewTestCase( new Date(946713600000),
   1.105 +		"new Date(946713600000)",
   1.106 +		[946713600000,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
   1.107 +
   1.108 +// Dates around 1900
   1.109 +
   1.110 +addNewTestCase( new Date(-2208988800000),
   1.111 +		"new Date(-2208988800000)",
   1.112 +		[-2208988800000,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
   1.113 +
   1.114 +addNewTestCase( new Date(-2208988800001),
   1.115 +		"new Date(-2208988800001)",
   1.116 +		[-2208988800001,1899,11,31,0,23,59,59,999,1899,11,31,0,15,59,59,999] );
   1.117 +
   1.118 +addNewTestCase( new Date(-2208960000001),
   1.119 +		"new Date(-2208960000001)",
   1.120 +		[-2208960000001,1900,0,1,1,7,59,59,0,1899,11,31,0,23,59,59,999] );
   1.121 +addNewTestCase( new Date(-2208960000000),
   1.122 +		"new Date(-2208960000000)",
   1.123 +		[-2208960000000,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
   1.124 +addNewTestCase( new Date(-2208959999999),
   1.125 +		"new Date(-2208959999999)",
   1.126 +		[-2208959999999,1900,0,1,1,8,0,0,1,1900,0,1,1,0,0,0,1] );
   1.127 +
   1.128 +// Dates around Feb 29, 2000
   1.129 +
   1.130 +var PST_FEB_29_2000 = UTC_FEB_29_2000 + 8*msPerHour;
   1.131 +
   1.132 +addNewTestCase( new Date(UTC_FEB_29_2000),
   1.133 +		"new Date(" + UTC_FEB_29_2000 +")",
   1.134 +		[UTC_FEB_29_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] );
   1.135 +addNewTestCase( new Date(PST_FEB_29_2000),
   1.136 +		"new Date(" + PST_FEB_29_2000 +")",
   1.137 +		[PST_FEB_29_2000,2000,0,1,6,8.0,0,0,2000,0,1,6,0,0,0,0]);
   1.138 +
   1.139 +// Dates around Jan 1 2005
   1.140 +
   1.141 +var PST_JAN_1_2005 = UTC_JAN_1_2005 + 8*msPerHour;
   1.142 +
   1.143 +addNewTestCase( new Date(UTC_JAN_1_2005),
   1.144 +		"new Date("+ UTC_JAN_1_2005 +")",
   1.145 +		[UTC_JAN_1_2005,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] );
   1.146 +addNewTestCase( new Date(PST_JAN_1_2005),
   1.147 +		"new Date("+ PST_JAN_1_2005 +")",
   1.148 +		[PST_JAN_1_2005,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] );
   1.149 +
   1.150 +
   1.151 +test();
   1.152 +
   1.153 +function addNewTestCase( DateCase, DateString, ResultArray ) {
   1.154 +  DateCase = DateCase;
   1.155 +
   1.156 +  new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME],       DateCase.getTime() );
   1.157 +  new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME],       DateCase.valueOf() );
   1.158 +  new TestCase( SECTION, "Date.parse(" + DateCase.toString() +")",    Math.floor(ResultArray[TIME]/1000)*1000,  Date.parse(DateCase.toString()) );
   1.159 +  new TestCase( SECTION, "Date.parse(" + DateCase.toGMTString() +")", Math.floor(ResultArray[TIME]/1000)*1000,  Date.parse(DateCase.toGMTString()) );
   1.160 +}

mercurial