blob: 374960cdb6980c57a30ace1a589dee6bb3a380c4 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// Copyright 2013 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28// Test if resolvedOptions() returns expected fields/values.
29
30// Default (year, month, day) formatter.
31var dtfDefault = Intl.DateTimeFormat('en-US');
32var resolved = dtfDefault.resolvedOptions();
33
34assertTrue(resolved.hasOwnProperty('locale'));
35assertEquals('en-US', resolved.locale);
36assertTrue(resolved.hasOwnProperty('numberingSystem'));
37assertEquals('latn', resolved.numberingSystem);
38assertTrue(resolved.hasOwnProperty('calendar'));
39assertEquals('gregory', resolved.calendar);
40assertTrue(resolved.hasOwnProperty('timeZone'));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000041// TODO(littledan): getDefaultTimeZone() is not available from JavaScript
42// assertEquals(getDefaultTimeZone(), resolved.timeZone);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000043// These are in by default.
44assertTrue(resolved.hasOwnProperty('year'));
45assertEquals('numeric', resolved.year);
46assertTrue(resolved.hasOwnProperty('month'));
47assertEquals('numeric', resolved.month);
48assertTrue(resolved.hasOwnProperty('day'));
49assertEquals('numeric', resolved.day);
50// These shouldn't be in by default.
51assertFalse(resolved.hasOwnProperty('era'));
52assertFalse(resolved.hasOwnProperty('timeZoneName'));
53assertFalse(resolved.hasOwnProperty('weekday'));
54assertFalse(resolved.hasOwnProperty('hour12'));
55assertFalse(resolved.hasOwnProperty('hour'));
56assertFalse(resolved.hasOwnProperty('minute'));
57assertFalse(resolved.hasOwnProperty('second'));
58
59// Time formatter.
60var dtfTime = Intl.DateTimeFormat(
61 'sr-RS', {hour: 'numeric', minute: 'numeric', second: 'numeric'});
62resolved = dtfTime.resolvedOptions();
63
64assertTrue(resolved.hasOwnProperty('locale'));
65assertTrue(resolved.hasOwnProperty('numberingSystem'));
66assertTrue(resolved.hasOwnProperty('calendar'));
67assertTrue(resolved.hasOwnProperty('timeZone'));
68assertTrue(resolved.hasOwnProperty('hour12'));
69assertEquals(false, resolved.hour12);
70assertTrue(resolved.hasOwnProperty('hour'));
71assertEquals('2-digit', resolved.hour);
72assertTrue(resolved.hasOwnProperty('minute'));
73assertEquals('2-digit', resolved.minute);
74assertTrue(resolved.hasOwnProperty('second'));
75assertEquals('2-digit', resolved.second);
76// Didn't ask for them.
77assertFalse(resolved.hasOwnProperty('year'));
78assertFalse(resolved.hasOwnProperty('month'));
79assertFalse(resolved.hasOwnProperty('day'));
80assertFalse(resolved.hasOwnProperty('era'));
81assertFalse(resolved.hasOwnProperty('timeZoneName'));
82assertFalse(resolved.hasOwnProperty('weekday'));
83
84// Full formatter.
85var dtfFull = Intl.DateTimeFormat(
86 'en-US', {weekday: 'short', era: 'short', year: 'numeric', month: 'short',
87 day: 'numeric', hour: 'numeric', minute: 'numeric',
88 second: 'numeric', timeZoneName: 'short', timeZone: 'UTC'});
89resolved = dtfFull.resolvedOptions();
90
91assertTrue(resolved.hasOwnProperty('locale'));
92assertTrue(resolved.hasOwnProperty('numberingSystem'));
93assertTrue(resolved.hasOwnProperty('calendar'));
94assertTrue(resolved.hasOwnProperty('timeZone'));
95assertTrue(resolved.hasOwnProperty('hour12'));
96assertEquals(true, resolved.hour12);
97assertTrue(resolved.hasOwnProperty('hour'));
98assertTrue(resolved.hasOwnProperty('minute'));
99assertTrue(resolved.hasOwnProperty('second'));
100assertTrue(resolved.hasOwnProperty('year'));
101assertTrue(resolved.hasOwnProperty('month'));
102assertTrue(resolved.hasOwnProperty('day'));
103assertTrue(resolved.hasOwnProperty('era'));
104assertEquals('short', resolved.era);
105assertTrue(resolved.hasOwnProperty('timeZoneName'));
106assertEquals('short', resolved.timeZoneName);
107assertTrue(resolved.hasOwnProperty('weekday'));
108assertEquals('short', resolved.weekday);