Debian Codegraph @

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

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2
3 const defaultLocale = "en-US";
4 const defaultDate = Date.UTC(2012, 12-1, 6, 12, 0, 0);
5 const defaultOptions = {
6 year: "numeric", month: "numeric", day: "numeric",
7 hour: "numeric", minute: "numeric", second: "numeric",
8 };
9 const longFormatOptions = Object.assign({}, defaultOptions, {
10 month: "long"
11 });
12 const tzNameFormatOptions = Object.assign({}, defaultOptions, {
13 timeZoneName: "short"
14 });
15
16 const tzMapper = [
17 x => x,
18 x => x.toUpperCase(),
19 x => x.toLowerCase(),
20 ];
21
22 const tests = [
23 {
24 timeZone: "UTC",
25 result: "12/6/2012, 12:00:00 PM",
26 },
27 {
28 timeZone: "America/Los_Angeles",
29 result: "12/6/2012, 4:00:00 AM",
30 },
31 {
32 timeZone: "America/New_York",
33 options: tzNameFormatOptions,
34 result: "12/6/2012, 7:00:00 AM EST",
35 },
36 {
37 timeZone: "America/Caracas",
38 result: "12/6/2012, 7:30:00 AM",
39 },
40 {
41 timeZone: "Europe/London",
42 result: "12/6/2012, 12:00:00 PM",
43 },
44 {
45 timeZone: "Africa/Casablanca",
46 locale: "ar-MA-u-ca-islamicc", options: longFormatOptions,
47 result: "22 محرم 1434 هـ في 12:00:00",
48 },
49 {
50 timeZone: "Europe/Berlin",
51 locale: "de-DE", options: tzNameFormatOptions,
52 result: "6.12.2012, 13:00:00 MEZ",
53 },
54 {
55 timeZone: "Asia/Kathmandu",
56 result: "12/6/2012, 5:45:00 PM",
57 },
58 {
59 timeZone: "Asia/Bangkok",
60 locale: "th-th-u-nu-thai", options: longFormatOptions,
61 result: "๖ ธันวาคม ๒๕๕๕ เวลา ๑๙:๐๐:๐๐",
62 },
63 {
64 timeZone: "Asia/Tokyo",
65 locale: "ja-JP", options: longFormatOptions,
66 result: "2012年12月6日 21:00:00",
67 },
68 {
69 timeZone: "Australia/Lord_Howe",
70 result: "12/6/2012, 11:00:00 PM",
71 },
72 {
73 timeZone: "Australia/Lord_Howe",
74 date: Date.UTC(2012, 7-1, 6, 12, 0, 0),
75 result: "7/6/2012, 10:30:00 PM",
76 },
77 {
78 timeZone: "Pacific/Kiritimati",
79 date: Date.UTC(1978, 12-1, 6, 12, 0, 0),
80 result: "12/6/1978, 1:20:00 AM",
81 },
82 {
83 timeZone: "Africa/Monrovia",
84 date: Date.UTC(1971, 12-1, 6, 12, 0, 0),
85 result: "12/6/1971, 11:15:30 AM",
86 },
87 {
88 timeZone: "Asia/Riyadh",
89 date: Date.UTC(1946, 12-1, 6, 12, 0, 0),
90 result: "12/6/1946, 3:06:52 PM",
91 },
92 ];
93
94 for (let {timeZone, result, locale = defaultLocale, date = defaultDate, options = defaultOptions} of tests) {
95 for (let map of tzMapper) {
96 let dtf = new Intl.DateTimeFormat(locale, Object.assign({timeZone: map(timeZone)}, options));
97 assertEq(dtf.format(date), result);
98 assertEq(dtf.resolvedOptions().timeZone, timeZone);
99 }
100 }
101
102
103 if (typeof reportCompare === "function")
104 reportCompare(0, 0, "ok");