Debian Codegraph @

js/src/tests/non262/Intl/DateTimeFormat/dateTimeStyle.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 // Date style
7
8 var dtf = new Intl.DateTimeFormat("en-US", {dateStyle: 'long'});
9 assertEq(dtf.resolvedOptions().dateStyle, 'long');
10 assertEq(dtf.resolvedOptions().hasOwnProperty('year'), false);
11 assertEq(dtf.resolvedOptions().hasOwnProperty('month'), false);
12 assertEq(dtf.resolvedOptions().hasOwnProperty('day'), false);
13
14 // Time style
15
16 var dtf = new Intl.DateTimeFormat("en-US", {timeStyle: 'long'});
17 assertEq(dtf.resolvedOptions().timeStyle, 'long');
18 assertEq(dtf.resolvedOptions().hasOwnProperty('hour'), false);
19 assertEq(dtf.resolvedOptions().hasOwnProperty('minute'), false);
20 assertEq(dtf.resolvedOptions().hasOwnProperty('second'), false);
21
22 // Date/Time style
23
24 var dtf = new Intl.DateTimeFormat("en-US", {dateStyle: 'medium', timeStyle: 'medium'});
25 assertEq(dtf.resolvedOptions().timeStyle, 'medium');
26 assertEq(dtf.resolvedOptions().dateStyle, 'medium');
27 assertEq(dtf.resolvedOptions().hasOwnProperty('hour'), false);
28 assertEq(dtf.resolvedOptions().hasOwnProperty('minute'), false);
29 assertEq(dtf.resolvedOptions().hasOwnProperty('second'), false);
30 assertEq(dtf.resolvedOptions().hasOwnProperty('year'), false);
31 assertEq(dtf.resolvedOptions().hasOwnProperty('month'), false);
32 assertEq(dtf.resolvedOptions().hasOwnProperty('day'), false);
33
34 // Error when mixing date/timeStyle with other date-time options.
35
36 assertThrowsInstanceOf(() => {
37 new Intl.DateTimeFormat("en-US", {dateStyle: 'medium', year: 'numeric'});
38 }, TypeError);
39
40 assertThrowsInstanceOf(() => {
41 new Intl.DateTimeFormat("en-US", {timeStyle: 'medium', year: 'numeric'});
42 }, TypeError);
43
44 // Error when using dateStyle in toLocaleTimeString.
45
46 assertThrowsInstanceOf(() => {
47 new Date().toLocaleTimeString("en-US", {dateStyle: 'long'});
48 }, TypeError);
49
50 // Error when using dateStyle in toLocaleDateString.
51
52 assertThrowsInstanceOf(() => {
53 new Date().toLocaleDateString("en-US", {timeStyle: 'long'});
54 }, TypeError);
55
56 if (typeof reportCompare === "function")
57 reportCompare(0, 0, 'ok');