| 1 |
// |reftest| skip-if(!this.hasOwnProperty("Intl")) |
| 2 |
|
| 3 |
if (typeof getAvailableLocalesOf === "undefined") { |
| 4 |
var getAvailableLocalesOf = SpecialPowers.Cu.getJSTestingFunctions().getAvailableLocalesOf; |
| 5 |
} |
| 6 |
|
| 7 |
// Retrieve all available locales of Intl.DateTimeFormat. |
| 8 |
const available = getAvailableLocalesOf("DateTimeFormat"); |
| 9 |
|
| 10 |
const options = [ |
| 11 |
// Include "hour" to catch hour cycle differences. |
| 12 |
// |
| 13 |
// For example "ff-Latn-GH" (Fulah as spoken in Ghana) uses a 12-hour clock, |
| 14 |
// whereas "ff" (Fulah) uses a 24-hour clock. When the user creates the |
| 15 |
// formatter for "ff-GH", it should use the same formatter data as "ff-Latn-GH" |
| 16 |
// and it shouldn't fallback to "ff". |
| 17 |
{hour: "2-digit", minute: "2-digit", timeZone: "UTC"}, |
| 18 |
|
| 19 |
// Include "timeZoneName" to catch script differences, e.g traditional or |
| 20 |
// simplified Chinese characters. |
| 21 |
{timeZoneName: "long", timeZone: "America/Los_Angeles"}, |
| 22 |
]; |
| 23 |
|
| 24 |
// Pick a date after 12 pm to catch any hour cycle differences. |
| 25 |
const date = Date.UTC(2021, 6-1, 7, 15, 0); |
| 26 |
|
| 27 |
available.map(x => { |
| 28 |
return new Intl.Locale(x); |
| 29 |
}).filter(loc => { |
| 30 |
// Find all locales which have both a script and a region subtag. |
| 31 |
return loc.script && loc.region; |
| 32 |
}).filter(loc => { |
| 33 |
// Skip "sd-Deva-IN" and Fulah because of <https://unicode-org.atlassian.net/browse/ICU-21974>. |
| 34 |
return !((loc.language === "sd" && loc.script === "Deva" && loc.region === "IN") || |
| 35 |
(loc.language === "ff" && (loc.script === "Adlm" || loc.script === "Latn") && |
| 36 |
(loc.region === "GH" || loc.region === "GM" || loc.region === "LR" || loc.region === "SL")) |
| 37 |
); |
| 38 |
}).forEach(loc => { |
| 39 |
// Remove the script subtag from the locale. |
| 40 |
let noScript = new Intl.Locale(`${loc.language}-${loc.region}`); |
| 41 |
|
| 42 |
// Add the likely script subtag. |
| 43 |
let maximized = noScript.maximize(); |
| 44 |
|
| 45 |
for (let opt of options) { |
| 46 |
// Formatter for the locale without a script subtag. |
| 47 |
let df1 = new Intl.DateTimeFormat(noScript, opt); |
| 48 |
|
| 49 |
// Formatter for the locale with the likely script subtag added. |
| 50 |
let df2 = new Intl.DateTimeFormat(maximized, opt); |
| 51 |
|
| 52 |
// The output for the locale without a script subtag should match the output |
| 53 |
// with the likely script subtag added. |
| 54 |
assertEq(df1.format(date), df2.format(date), `Mismatch for locale "${noScript}" (${maximized})`); |
| 55 |
} |
| 56 |
}); |
| 57 |
|
| 58 |
if (typeof reportCompare === "function") |
| 59 |
reportCompare(0, 0, "ok"); |