1bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// Copyright 2013 the V8 project authors. All rights reserved.
2bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// Redistribution and use in source and binary forms, with or without
3bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// modification, are permitted provided that the following conditions are
4bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// met:
5bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//
6bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//     * Redistributions of source code must retain the above copyright
7bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//       notice, this list of conditions and the following disclaimer.
8bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//     * Redistributions in binary form must reproduce the above
9bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//       copyright notice, this list of conditions and the following
10bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//       disclaimer in the documentation and/or other materials provided
11bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//       with the distribution.
12bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//     * Neither the name of Google Inc. nor the names of its
13bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//       contributors may be used to endorse or promote products derived
14bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//       from this software without specific prior written permission.
15bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org//
16bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org
28bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// Testing v8Parse method for date and time pattern.
29bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// Month is represented as a short name.
30bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org
31bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.orgvar dtf = new Intl.DateTimeFormat(['en'],
32bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org                                  {year: 'numeric', month: 'short',
332efc3e46d2de48d8859520ee7fe035c02108509bmstarzinger@chromium.org                                   day: 'numeric',
342efc3e46d2de48d8859520ee7fe035c02108509bmstarzinger@chromium.org                                   timeZone: 'America/Los_Angeles'});
35bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org
36bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// Make sure we have pattern we expect (may change in the future).
37bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.orgassertEquals('MMM d, y', dtf.resolved.pattern);
38bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org
392efc3e46d2de48d8859520ee7fe035c02108509bmstarzinger@chromium.orgvar date = dtf.v8Parse('Feb 4, 1974');
402efc3e46d2de48d8859520ee7fe035c02108509bmstarzinger@chromium.orgassertEquals(1974, date.getUTCFullYear());
412efc3e46d2de48d8859520ee7fe035c02108509bmstarzinger@chromium.orgassertEquals(1, date.getUTCMonth());
422efc3e46d2de48d8859520ee7fe035c02108509bmstarzinger@chromium.orgassertEquals(4, date.getUTCDate());
43bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org
44bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// Missing , in the pattern.
452efc3e46d2de48d8859520ee7fe035c02108509bmstarzinger@chromium.orgassertEquals(undefined, dtf.v8Parse('Feb 4 1974'));
46bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org
47bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// Extra "th" after 4 in the pattern.
482efc3e46d2de48d8859520ee7fe035c02108509bmstarzinger@chromium.orgassertEquals(undefined, dtf.v8Parse('Feb 4th, 1974'));
49bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org
50bee51999422c0eeaae85ed99b5c0bd4126510ff1danno@chromium.org// Wrong pattern.
512efc3e46d2de48d8859520ee7fe035c02108509bmstarzinger@chromium.orgassertEquals(undefined, dtf.v8Parse('2/4/1974'));
52