mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibJS: Change default time display options to "always" for digital style
This is a normative change in the Intl.DurationFormat proposal. See:
d28076b
This commit is contained in:
parent
5f4c59e2c1
commit
82e730eba1
2 changed files with 48 additions and 13 deletions
|
@ -244,23 +244,32 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, String
|
||||||
|
|
||||||
// 3. If style is undefined, then
|
// 3. If style is undefined, then
|
||||||
if (style_value.is_undefined()) {
|
if (style_value.is_undefined()) {
|
||||||
// a. Set displayDefault to "auto".
|
// a. If baseStyle is "digital", then
|
||||||
display_default = "auto"sv;
|
|
||||||
|
|
||||||
// b. If baseStyle is "digital", then
|
|
||||||
if (base_style == "digital"sv) {
|
if (base_style == "digital"sv) {
|
||||||
// i. Set style to digitalBase.
|
// i. If unit is not one of "hours", "minutes", or "seconds", then
|
||||||
|
if (!unit.is_one_of("hours"sv, "minutes"sv, "seconds"sv)) {
|
||||||
|
// 1. Set displayDefault to "auto".
|
||||||
|
display_default = "auto"sv;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ii. Set style to digitalBase.
|
||||||
style = digital_base;
|
style = digital_base;
|
||||||
}
|
}
|
||||||
// c. Else if prevStyle is "numeric" or "2-digit", then
|
// b. Else,
|
||||||
else if (previous_style == "numeric"sv || previous_style == "2-digit"sv) {
|
|
||||||
// i. Set style to "numeric".
|
|
||||||
style = "numeric"sv;
|
|
||||||
}
|
|
||||||
// d. Else,
|
|
||||||
else {
|
else {
|
||||||
// i. Set style to baseStyle.
|
// i. Set displayDefault to "auto".
|
||||||
style = base_style;
|
display_default = "auto"sv;
|
||||||
|
|
||||||
|
// ii. If prevStyle is "numeric" or "2-digit", then
|
||||||
|
if (previous_style == "numeric"sv || previous_style == "2-digit"sv) {
|
||||||
|
// 1. Set style to "numeric".
|
||||||
|
style = "numeric"sv;
|
||||||
|
}
|
||||||
|
// iii. Else,
|
||||||
|
else {
|
||||||
|
// 1. Set style to baseStyle.
|
||||||
|
style = base_style;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
style = style_value.as_string().string();
|
style = style_value.as_string().string();
|
||||||
|
|
|
@ -62,6 +62,32 @@ describe("correct behavior", () => {
|
||||||
}).format(duration)
|
}).format(duration)
|
||||||
).toBe("1 J, 2 M, 3 W, 3 T, 4 Std., 5 Min., 6 Sek., 7 ms und 8,009 μs");
|
).toBe("1 J, 2 M, 3 W, 3 T, 4 Std., 5 Min., 6 Sek., 7 ms und 8,009 μs");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("always show time fields for digital style", () => {
|
||||||
|
const duration1 = {
|
||||||
|
years: 1,
|
||||||
|
months: 2,
|
||||||
|
weeks: 3,
|
||||||
|
days: 3,
|
||||||
|
};
|
||||||
|
const duration2 = {
|
||||||
|
years: 1,
|
||||||
|
months: 2,
|
||||||
|
weeks: 3,
|
||||||
|
days: 3,
|
||||||
|
hours: 4,
|
||||||
|
minutes: 5,
|
||||||
|
seconds: 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
const en = new Intl.DurationFormat("en", { style: "digital" });
|
||||||
|
expect(en.format(duration1)).toBe("1 yr 2 mths 3 wks 3 days 0:00:00");
|
||||||
|
expect(en.format(duration2)).toBe("1 yr 2 mths 3 wks 3 days 4:05:06");
|
||||||
|
|
||||||
|
const de = new Intl.DurationFormat("de", { style: "digital" });
|
||||||
|
expect(de.format(duration1)).toBe("1 J, 2 Mon., 3 Wo., 3 Tg. und 0:00:00");
|
||||||
|
expect(de.format(duration2)).toBe("1 J, 2 Mon., 3 Wo., 3 Tg. und 4:05:06");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("errors", () => {
|
describe("errors", () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue