michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: 15.9.4.2.js michael@0: ECMA Section: 15.9.4.2 Date.parse() michael@0: Description: The parse() function applies the to ToString() operator michael@0: to its argument and interprets the resulting string as michael@0: a date. It returns a number, the UTC time value michael@0: corresponding to the date. michael@0: michael@0: The string may be interpreted as a local time, a UTC michael@0: time, or a time in some other time zone, depending on michael@0: the contents of the string. michael@0: michael@0: (need to test strings containing stuff with the time michael@0: zone specified, and verify that parse() returns the michael@0: correct GMT time) michael@0: michael@0: so for any Date object x, all of these things should michael@0: be equal: michael@0: michael@0: value tested in function: michael@0: x.valueOf() test_value() michael@0: Date.parse(x.toString()) test_tostring() michael@0: Date.parse(x.toGMTString()) test_togmt() michael@0: michael@0: Date.parse(x.toLocaleString()) is not required to michael@0: produce the same number value as the preceding three michael@0: expressions. in general the value produced by michael@0: Date.parse is implementation dependent when given any michael@0: string value that could not be produced in that michael@0: implementation by the toString or toGMTString method. michael@0: michael@0: value tested in function: michael@0: Date.parse( x.toLocaleString()) test_tolocale() michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 10 july 1997 michael@0: michael@0: */ michael@0: michael@0: var VERSION = "ECMA_1"; michael@0: startTest(); michael@0: var SECTION = "15.9.4.2"; michael@0: var TITLE = "Date.parse()"; michael@0: michael@0: var TIME = 0; michael@0: var UTC_YEAR = 1; michael@0: var UTC_MONTH = 2; michael@0: var UTC_DATE = 3; michael@0: var UTC_DAY = 4; michael@0: var UTC_HOURS = 5; michael@0: var UTC_MINUTES = 6; michael@0: var UTC_SECONDS = 7; michael@0: var UTC_MS = 8; michael@0: michael@0: var YEAR = 9; michael@0: var MONTH = 10; michael@0: var DATE = 11; michael@0: var DAY = 12; michael@0: var HOURS = 13; michael@0: var MINUTES = 14; michael@0: var SECONDS = 15; michael@0: var MS = 16; michael@0: var TYPEOF = "object"; michael@0: michael@0: // for TCMS, the gTestcases array must be global. michael@0: writeHeaderToLog("15.9.4.2 Date.parse()" ); michael@0: michael@0: // Dates around 1970 michael@0: michael@0: addNewTestCase( new Date(0), michael@0: "new Date(0)", michael@0: [0,1970,0,1,4,0,0,0,0,1969,11,31,3,16,0,0,0] ); michael@0: michael@0: addNewTestCase( new Date(-1), michael@0: "new Date(-1)", michael@0: [-1,1969,11,31,3,23,59,59,999,1969,11,31,3,15,59,59,999] ); michael@0: addNewTestCase( new Date(28799999), michael@0: "new Date(28799999)", michael@0: [28799999,1970,0,1,4,7,59,59,999,1969,11,31,3,23,59,59,999] ); michael@0: addNewTestCase( new Date(28800000), michael@0: "new Date(28800000)", michael@0: [28800000,1970,0,1,4,8,0,0,0,1970,0,1,4,0,0,0,0] ); michael@0: michael@0: // Dates around 2000 michael@0: michael@0: addNewTestCase( new Date(946684799999), michael@0: "new Date(946684799999)", michael@0: [946684799999,1999,11,31,5,23,59,59,999,1999,11,31,5,15,59,59,999] ); michael@0: addNewTestCase( new Date(946713599999), michael@0: "new Date(946713599999)", michael@0: [946713599999,2000,0,1,6,7,59,59,999,1999,11,31,5,23,59,59,999] ); michael@0: addNewTestCase( new Date(946684800000), michael@0: "new Date(946684800000)", michael@0: [946684800000,2000,0,1,6,0,0,0,0,1999,11,31,5, 16,0,0,0] ); michael@0: addNewTestCase( new Date(946713600000), michael@0: "new Date(946713600000)", michael@0: [946713600000,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] ); michael@0: michael@0: // Dates around 1900 michael@0: michael@0: addNewTestCase( new Date(-2208988800000), michael@0: "new Date(-2208988800000)", michael@0: [-2208988800000,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] ); michael@0: michael@0: addNewTestCase( new Date(-2208988800001), michael@0: "new Date(-2208988800001)", michael@0: [-2208988800001,1899,11,31,0,23,59,59,999,1899,11,31,0,15,59,59,999] ); michael@0: michael@0: addNewTestCase( new Date(-2208960000001), michael@0: "new Date(-2208960000001)", michael@0: [-2208960000001,1900,0,1,1,7,59,59,0,1899,11,31,0,23,59,59,999] ); michael@0: addNewTestCase( new Date(-2208960000000), michael@0: "new Date(-2208960000000)", michael@0: [-2208960000000,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] ); michael@0: addNewTestCase( new Date(-2208959999999), michael@0: "new Date(-2208959999999)", michael@0: [-2208959999999,1900,0,1,1,8,0,0,1,1900,0,1,1,0,0,0,1] ); michael@0: michael@0: // Dates around Feb 29, 2000 michael@0: michael@0: var PST_FEB_29_2000 = UTC_FEB_29_2000 + 8*msPerHour; michael@0: michael@0: addNewTestCase( new Date(UTC_FEB_29_2000), michael@0: "new Date(" + UTC_FEB_29_2000 +")", michael@0: [UTC_FEB_29_2000,2000,0,1,6,0,0,0,0,1999,11,31,5,16,0,0,0] ); michael@0: addNewTestCase( new Date(PST_FEB_29_2000), michael@0: "new Date(" + PST_FEB_29_2000 +")", michael@0: [PST_FEB_29_2000,2000,0,1,6,8.0,0,0,2000,0,1,6,0,0,0,0]); michael@0: michael@0: // Dates around Jan 1 2005 michael@0: michael@0: var PST_JAN_1_2005 = UTC_JAN_1_2005 + 8*msPerHour; michael@0: michael@0: addNewTestCase( new Date(UTC_JAN_1_2005), michael@0: "new Date("+ UTC_JAN_1_2005 +")", michael@0: [UTC_JAN_1_2005,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] ); michael@0: addNewTestCase( new Date(PST_JAN_1_2005), michael@0: "new Date("+ PST_JAN_1_2005 +")", michael@0: [PST_JAN_1_2005,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] ); michael@0: michael@0: michael@0: test(); michael@0: michael@0: function addNewTestCase( DateCase, DateString, ResultArray ) { michael@0: DateCase = DateCase; michael@0: michael@0: new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME], DateCase.getTime() ); michael@0: new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME], DateCase.valueOf() ); michael@0: new TestCase( SECTION, "Date.parse(" + DateCase.toString() +")", Math.floor(ResultArray[TIME]/1000)*1000, Date.parse(DateCase.toString()) ); michael@0: new TestCase( SECTION, "Date.parse(" + DateCase.toGMTString() +")", Math.floor(ResultArray[TIME]/1000)*1000, Date.parse(DateCase.toGMTString()) ); michael@0: }