From 4686989582085da6f557c9d7f3b8de41412e779c Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 1 Nov 2022 09:15:11 -0400 Subject: [PATCH] LibJS: Map DurationFormat's list style to "short" when it is "digital" This is a normative change in the Intl.DurationFormat proposal. See: https://github.com/tc39/proposal-intl-duration-format/commit/7495e32 --- Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp | 4 ++-- .../DurationFormat/DurationFormat.prototype.format.js | 6 +++--- .../DurationFormat.prototype.formatToParts.js | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index e07a8a0a7b..35a66401aa 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -510,8 +510,8 @@ Vector partition_duration_format_pattern(VM& vm, DurationForma // 7. If listStyle is "digital", then if (list_style == DurationFormat::Style::Digital) { - // a. Set listStyle to "narrow". - list_style = DurationFormat::Style::Narrow; + // a. Set listStyle to "short". + list_style = DurationFormat::Style::Short; } auto unicode_list_style = ::Locale::style_to_string(static_cast<::Locale::Style>(list_style)); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.format.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.format.js index fc3a04c4ae..d7de5ff780 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.format.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.format.js @@ -32,7 +32,7 @@ describe("correct behavior", () => { "1y 2m 3w 3d 4h 5m 6s 7ms 8μs 9ns" ); expect(new Intl.DurationFormat("en", { style: "digital" }).format(duration)).toBe( - "1 yr 2 mths 3 wks 3 days 4:05:06" + "1 yr, 2 mths, 3 wks, 3 days, 4:05:06" ); expect( new Intl.DurationFormat("en", { @@ -81,8 +81,8 @@ describe("correct behavior", () => { }; 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"); + 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"); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.formatToParts.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.formatToParts.js index 6098cb1efa..be12c713a0 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.formatToParts.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.formatToParts.js @@ -124,13 +124,13 @@ describe("correct behavior", () => { expect(new Intl.DurationFormat("en", { style: "digital" }).formatToParts(duration)).toEqual( [ { type: "element", value: "1 yr" }, - { type: "literal", value: " " }, + { type: "literal", value: ", " }, { type: "element", value: "2 mths" }, - { type: "literal", value: " " }, + { type: "literal", value: ", " }, { type: "element", value: "3 wks" }, - { type: "literal", value: " " }, + { type: "literal", value: ", " }, { type: "element", value: "3 days" }, - { type: "literal", value: " " }, + { type: "literal", value: ", " }, { type: "element", value: "4:05:06" }, ] );