1// Copyright 2013 the V8 project authors. All rights reserved. 2// Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions 6// are met: 7// 1. Redistributions of source code must retain the above copyright 8// notice, this list of conditions and the following disclaimer. 9// 2. Redistributions in binary form must reproduce the above copyright 10// notice, this list of conditions and the following disclaimer in the 11// documentation and/or other materials provided with the distribution. 12// 13// THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16// DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24description( 25"test of JavaScript date parsing (comments in parentheses)" 26); 27 28function testDateParse(date, numericResult) 29{ 30 if (numericResult == "NaN") { 31 shouldBeNaN('Date.parse("' + date + '")'); 32 shouldBeNaN('Date.parse("' + date.toUpperCase() + '")'); 33 shouldBeNaN('Date.parse("' + date.toLowerCase() + '")'); 34 } else { 35 shouldBeTrue('Date.parse("' + date + '") == ' + numericResult); 36 shouldBeTrue('Date.parse("' + date.toUpperCase() + '") == ' + numericResult); 37 shouldBeTrue('Date.parse("' + date.toLowerCase() + '") == ' + numericResult); 38 } 39} 40 41var timeZoneOffset = Date.parse(" Dec 25 1995 1:30 ") - Date.parse(" Dec 25 1995 1:30 GMT "); 42 43testDateParse("Dec ((27) 26 (24)) 25 1995 1:30 PM UTC", "819898200000"); 44testDateParse("Dec 25 1995 1:30 PM UTC (", "819898200000"); 45testDateParse("Dec 25 1995 1:30 (PM)) UTC", "NaN"); 46testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) GMT (EST)", "819849600000"); 47testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996)", "819849600000 + timeZoneOffset"); 48 49testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40) GMT (EST)", "819855000000"); 50testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40)", "819855000000 + timeZoneOffset"); 51testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 ", "819855000000 + timeZoneOffset"); 52testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 AM (1:40 PM) GMT (EST)", "819855000000"); 53testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 AM (1:40 PM)", "819855000000 + timeZoneOffset"); 54testDateParse("Dec 25 1995 1:30( )AM (PM)", "NaN"); 55testDateParse("Dec 25 1995 1:30 AM (PM)", "819855000000 + timeZoneOffset"); 56 57testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 13:30 (13:40) GMT (PST)", "819898200000"); 58testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 13:30 (13:40)", "819898200000 + timeZoneOffset"); 59testDateParse('(Nov) Dec (24) 25 (26) 13:30 (13:40) 1995 (1996)', "819898200000 + timeZoneOffset"); 60testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 13:30 (13:40) ", "819898200000 + timeZoneOffset"); 61testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40) PM (AM) GMT (PST)", "819898200000"); 62testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40) PM (AM)", "819898200000 + timeZoneOffset"); 63testDateParse("Dec 25 1995 1:30(AM)PM", "NaN"); 64testDateParse("Dec 25 1995 1:30 (AM)PM ", "819898200000 + timeZoneOffset"); 65 66testDateParse("Dec 25 1995 (PDT)UTC(PST)", "819849600000"); 67testDateParse("Dec 25 1995 (PDT)UT(PST)", "819849600000"); 68testDateParse("Dec 25 1995 (UTC)PST(GMT)", "819878400000"); 69testDateParse("Dec 25 1995 (UTC)PDT(GMT)", "819874800000"); 70 71testDateParse("Dec 25 1995 1:30 (PDT)UTC(PST)", "819855000000"); 72testDateParse("Dec 25 1995 1:30 (PDT)UT(PST)", "819855000000"); 73testDateParse("Dec 25 1995 1:30 (UTC)PST(GMT)", "819883800000"); 74testDateParse("Dec 25 1995 1:30 (UTC)PDT(GMT)", "819880200000"); 75 76testDateParse("Dec 25 1995 1:30 (AM) PM (PST) UTC", "819898200000"); 77testDateParse("Dec 25 1995 1:30 PM (AM) (PST) UT", "819898200000"); 78testDateParse("Dec 25 1995 1:30 PM (AM) (UTC) PST", "819927000000"); 79testDateParse("Dec 25 1995 1:30 (AM) PM PDT (UTC)", "819923400000"); 80 81testDateParse("Dec 25 1995 XXX (GMT)", "NaN"); 82testDateParse("Dec 25 1995 1:30 XXX (GMT)", "NaN"); 83 84testDateParse("Dec 25 1995 1:30 U(TC)", "NaN"); 85testDateParse("Dec 25 1995 1:30 V(UTC)", "NaN"); 86testDateParse("Dec 25 1995 1:30 (UTC)W", "NaN"); 87testDateParse("Dec 25 1995 1:30 (GMT)X", "NaN"); 88 89testDateParse("Dec 25 1995 0:30 (PM) GMT", "819851400000"); 90testDateParse("Dec 25 1995 (1)0:30 AM GMT", "819851400000"); 91testDateParse("Dec 25 1995 (1)0:30 PM GMT", "819894600000"); 92 93testDateParse("Anf(Dec) 25 1995 GMT", "NaN"); 94 95testDateParse("(Sat) Wed (Nov) Dec (Nov) 25 1995 1:30 GMT", "819855000000"); 96testDateParse("Wed (comment 1) (comment 2) Dec 25 1995 1:30 GMT", "819855000000"); 97testDateParse("Wed(comment 1) (comment 2) Dec 25 1995 1:30 GMT", "819855000000"); 98testDateParse("We(comment 1) (comment 2) Dec 25 1995 1:30 GMT", "819855000000"); 99