mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:27:35 +00:00
LibJS+LibUnicode: Add "microsecond" and "nanosecond" as sanctioned units
This is a normative change in the ECMA-402 spec. See:
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
|
// 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.
|
// 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();
|
constexpr auto sanctioned_units = JS::Intl::sanctioned_single_unit_identifiers();
|
||||||
if (find(sanctioned_units.begin(), sanctioned_units.end(), unit_name) != sanctioned_units.end())
|
return 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();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto parse_units_object = [&](auto const& units_object, Locale::Style style) {
|
auto parse_units_object = [&](auto const& units_object, Locale::Style style) {
|
||||||
|
|
|
@ -40,6 +40,7 @@ constexpr auto sanctioned_single_unit_identifiers()
|
||||||
"megabit"sv,
|
"megabit"sv,
|
||||||
"megabyte"sv,
|
"megabyte"sv,
|
||||||
"meter"sv,
|
"meter"sv,
|
||||||
|
"microsecond"sv,
|
||||||
"mile"sv,
|
"mile"sv,
|
||||||
"mile-scandinavian"sv,
|
"mile-scandinavian"sv,
|
||||||
"milliliter"sv,
|
"milliliter"sv,
|
||||||
|
@ -47,6 +48,7 @@ constexpr auto sanctioned_single_unit_identifiers()
|
||||||
"millisecond"sv,
|
"millisecond"sv,
|
||||||
"minute"sv,
|
"minute"sv,
|
||||||
"month"sv,
|
"month"sv,
|
||||||
|
"nanosecond"sv,
|
||||||
"ounce"sv,
|
"ounce"sv,
|
||||||
"percent"sv,
|
"percent"sv,
|
||||||
"petabyte"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(1.2)).toBe("1.2 kilometers per hour");
|
||||||
expect(en2.format(123)).toBe("123 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", {
|
const ar = new Intl.NumberFormat("ar", {
|
||||||
style: "unit",
|
style: "unit",
|
||||||
unit: "foot",
|
unit: "foot",
|
||||||
|
@ -1556,6 +1565,15 @@ describe("style=unit", () => {
|
||||||
expect(en2.format(1.2)).toBe("1.2 km/h");
|
expect(en2.format(1.2)).toBe("1.2 km/h");
|
||||||
expect(en2.format(123)).toBe("123 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", {
|
const ar = new Intl.NumberFormat("ar", {
|
||||||
style: "unit",
|
style: "unit",
|
||||||
unit: "foot",
|
unit: "foot",
|
||||||
|
@ -1594,6 +1612,15 @@ describe("style=unit", () => {
|
||||||
expect(en2.format(1.2)).toBe("1.2km/h");
|
expect(en2.format(1.2)).toBe("1.2km/h");
|
||||||
expect(en2.format(123)).toBe("123km/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", {
|
const ar = new Intl.NumberFormat("ar", {
|
||||||
style: "unit",
|
style: "unit",
|
||||||
unit: "foot",
|
unit: "foot",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue