Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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 | |
| 24 | description( |
| 25 | "test of JavaScript date parsing (comments in parentheses)" |
| 26 | ); |
| 27 | |
| 28 | function 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 | |
| 41 | var timeZoneOffset = Date.parse(" Dec 25 1995 1:30 ") - Date.parse(" Dec 25 1995 1:30 GMT "); |
| 42 | |
| 43 | testDateParse("Dec ((27) 26 (24)) 25 1995 1:30 PM UTC", "819898200000"); |
| 44 | testDateParse("Dec 25 1995 1:30 PM UTC (", "819898200000"); |
| 45 | testDateParse("Dec 25 1995 1:30 (PM)) UTC", "NaN"); |
| 46 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) GMT (EST)", "819849600000"); |
| 47 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996)", "819849600000 + timeZoneOffset"); |
| 48 | |
| 49 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40) GMT (EST)", "819855000000"); |
| 50 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40)", "819855000000 + timeZoneOffset"); |
| 51 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 ", "819855000000 + timeZoneOffset"); |
| 52 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 AM (1:40 PM) GMT (EST)", "819855000000"); |
| 53 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 AM (1:40 PM)", "819855000000 + timeZoneOffset"); |
| 54 | testDateParse("Dec 25 1995 1:30( )AM (PM)", "NaN"); |
| 55 | testDateParse("Dec 25 1995 1:30 AM (PM)", "819855000000 + timeZoneOffset"); |
| 56 | |
| 57 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 13:30 (13:40) GMT (PST)", "819898200000"); |
| 58 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 13:30 (13:40)", "819898200000 + timeZoneOffset"); |
| 59 | testDateParse('(Nov) Dec (24) 25 (26) 13:30 (13:40) 1995 (1996)', "819898200000 + timeZoneOffset"); |
| 60 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 13:30 (13:40) ", "819898200000 + timeZoneOffset"); |
| 61 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40) PM (AM) GMT (PST)", "819898200000"); |
| 62 | testDateParse("(Nov) Dec (24) 25 (26) 1995 (1996) 1:30 (1:40) PM (AM)", "819898200000 + timeZoneOffset"); |
| 63 | testDateParse("Dec 25 1995 1:30(AM)PM", "NaN"); |
| 64 | testDateParse("Dec 25 1995 1:30 (AM)PM ", "819898200000 + timeZoneOffset"); |
| 65 | |
| 66 | testDateParse("Dec 25 1995 (PDT)UTC(PST)", "819849600000"); |
| 67 | testDateParse("Dec 25 1995 (PDT)UT(PST)", "819849600000"); |
| 68 | testDateParse("Dec 25 1995 (UTC)PST(GMT)", "819878400000"); |
| 69 | testDateParse("Dec 25 1995 (UTC)PDT(GMT)", "819874800000"); |
| 70 | |
| 71 | testDateParse("Dec 25 1995 1:30 (PDT)UTC(PST)", "819855000000"); |
| 72 | testDateParse("Dec 25 1995 1:30 (PDT)UT(PST)", "819855000000"); |
| 73 | testDateParse("Dec 25 1995 1:30 (UTC)PST(GMT)", "819883800000"); |
| 74 | testDateParse("Dec 25 1995 1:30 (UTC)PDT(GMT)", "819880200000"); |
| 75 | |
| 76 | testDateParse("Dec 25 1995 1:30 (AM) PM (PST) UTC", "819898200000"); |
| 77 | testDateParse("Dec 25 1995 1:30 PM (AM) (PST) UT", "819898200000"); |
| 78 | testDateParse("Dec 25 1995 1:30 PM (AM) (UTC) PST", "819927000000"); |
| 79 | testDateParse("Dec 25 1995 1:30 (AM) PM PDT (UTC)", "819923400000"); |
| 80 | |
| 81 | testDateParse("Dec 25 1995 XXX (GMT)", "NaN"); |
| 82 | testDateParse("Dec 25 1995 1:30 XXX (GMT)", "NaN"); |
| 83 | |
| 84 | testDateParse("Dec 25 1995 1:30 U(TC)", "NaN"); |
| 85 | testDateParse("Dec 25 1995 1:30 V(UTC)", "NaN"); |
| 86 | testDateParse("Dec 25 1995 1:30 (UTC)W", "NaN"); |
| 87 | testDateParse("Dec 25 1995 1:30 (GMT)X", "NaN"); |
| 88 | |
| 89 | testDateParse("Dec 25 1995 0:30 (PM) GMT", "819851400000"); |
| 90 | testDateParse("Dec 25 1995 (1)0:30 AM GMT", "819851400000"); |
| 91 | testDateParse("Dec 25 1995 (1)0:30 PM GMT", "819894600000"); |
| 92 | |
| 93 | testDateParse("Anf(Dec) 25 1995 GMT", "NaN"); |
| 94 | |
| 95 | testDateParse("(Sat) Wed (Nov) Dec (Nov) 25 1995 1:30 GMT", "819855000000"); |
| 96 | testDateParse("Wed (comment 1) (comment 2) Dec 25 1995 1:30 GMT", "819855000000"); |
| 97 | testDateParse("Wed(comment 1) (comment 2) Dec 25 1995 1:30 GMT", "819855000000"); |
| 98 | testDateParse("We(comment 1) (comment 2) Dec 25 1995 1:30 GMT", "819855000000"); |