mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibJS+LibUnicode: Add "microsecond" and "nanosecond" as sanctioned units
This is a normative change in the ECMA-402 spec. See: https://github.com/tc39/ecma402/commit/f627573
This commit is contained in:
parent
8ff0d35386
commit
a5bf32018f
3 changed files with 30 additions and 10 deletions
|
@ -638,10 +638,7 @@ static ErrorOr<void> parse_units(String locale_units_path, CLDR& cldr, LocaleDat
|
|||
// LibUnicode generally tries to avoid being directly dependent on ECMA-402, but this rather significantly reduces the amount
|
||||
// of data generated here, and ECMA-402 is currently the only consumer of this data.
|
||||
constexpr auto sanctioned_units = JS::Intl::sanctioned_single_unit_identifiers();
|
||||
if (find(sanctioned_units.begin(), sanctioned_units.end(), unit_name) != sanctioned_units.end())
|
||||
return true;
|
||||
static constexpr auto extra_sanctioned_units = JS::Intl::extra_sanctioned_single_unit_identifiers();
|
||||
return find(extra_sanctioned_units.begin(), extra_sanctioned_units.end(), unit_name) != extra_sanctioned_units.end();
|
||||
return find(sanctioned_units.begin(), sanctioned_units.end(), unit_name) != sanctioned_units.end();
|
||||
};
|
||||
|
||||
auto parse_units_object = [&](auto const& units_object, Locale::Style style) {
|
||||
|
|
|
@ -40,6 +40,7 @@ constexpr auto sanctioned_single_unit_identifiers()
|
|||
"megabit"sv,
|
||||
"megabyte"sv,
|
||||
"meter"sv,
|
||||
"microsecond"sv,
|
||||
"mile"sv,
|
||||
"mile-scandinavian"sv,
|
||||
"milliliter"sv,
|
||||
|
@ -47,6 +48,7 @@ constexpr auto sanctioned_single_unit_identifiers()
|
|||
"millisecond"sv,
|
||||
"minute"sv,
|
||||
"month"sv,
|
||||
"nanosecond"sv,
|
||||
"ounce"sv,
|
||||
"percent"sv,
|
||||
"petabyte"sv,
|
||||
|
@ -61,10 +63,4 @@ constexpr auto sanctioned_single_unit_identifiers()
|
|||
};
|
||||
}
|
||||
|
||||
// Additional single units used in ECMAScript required by the Intl.DurationFormat proposal
|
||||
constexpr auto extra_sanctioned_single_unit_identifiers()
|
||||
{
|
||||
return AK::Array { "microsecond"sv, "nanosecond"sv };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1518,6 +1518,15 @@ describe("style=unit", () => {
|
|||
expect(en2.format(1.2)).toBe("1.2 kilometers per hour");
|
||||
expect(en2.format(123)).toBe("123 kilometers per hour");
|
||||
|
||||
const en3 = new Intl.NumberFormat("en", {
|
||||
style: "unit",
|
||||
unit: "nanosecond",
|
||||
unitDisplay: "long",
|
||||
});
|
||||
expect(en3.format(1)).toBe("1 nanosecond");
|
||||
expect(en3.format(1.2)).toBe("1.2 nanoseconds");
|
||||
expect(en3.format(123)).toBe("123 nanoseconds");
|
||||
|
||||
const ar = new Intl.NumberFormat("ar", {
|
||||
style: "unit",
|
||||
unit: "foot",
|
||||
|
@ -1556,6 +1565,15 @@ describe("style=unit", () => {
|
|||
expect(en2.format(1.2)).toBe("1.2 km/h");
|
||||
expect(en2.format(123)).toBe("123 km/h");
|
||||
|
||||
const en3 = new Intl.NumberFormat("en", {
|
||||
style: "unit",
|
||||
unit: "nanosecond",
|
||||
unitDisplay: "short",
|
||||
});
|
||||
expect(en3.format(1)).toBe("1 ns");
|
||||
expect(en3.format(1.2)).toBe("1.2 ns");
|
||||
expect(en3.format(123)).toBe("123 ns");
|
||||
|
||||
const ar = new Intl.NumberFormat("ar", {
|
||||
style: "unit",
|
||||
unit: "foot",
|
||||
|
@ -1594,6 +1612,15 @@ describe("style=unit", () => {
|
|||
expect(en2.format(1.2)).toBe("1.2km/h");
|
||||
expect(en2.format(123)).toBe("123km/h");
|
||||
|
||||
const en3 = new Intl.NumberFormat("en", {
|
||||
style: "unit",
|
||||
unit: "nanosecond",
|
||||
unitDisplay: "narrow",
|
||||
});
|
||||
expect(en3.format(1)).toBe("1ns");
|
||||
expect(en3.format(1.2)).toBe("1.2ns");
|
||||
expect(en3.format(123)).toBe("123ns");
|
||||
|
||||
const ar = new Intl.NumberFormat("ar", {
|
||||
style: "unit",
|
||||
unit: "foot",
|
||||
|
|
Loading…
Add table
Reference in a new issue