diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-08-30 10:23:38 -0400 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-08-30 14:26:11 -0400 |
commit | d57b92da091e288186d7776cb4d6df056b48c061 (patch) | |
tree | fddd8274819bab5d1472bf8c3490431ad5ef3670 /Userland | |
parent | 765d01667043397cdef3642da0f59bee193a2975 (diff) | |
download | serenity-d57b92da091e288186d7776cb4d6df056b48c061.zip |
LibJS: Default to "short" for DurationFormat's style option
This is a normative change in the Intl.DurationFormat proposal. See:
https://github.com/tc39/proposal-intl-duration-format/commit/b289494
Diffstat (limited to 'Userland')
4 files changed, 33 insertions, 33 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp index fceeda7b66..5cede348cf 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp @@ -89,8 +89,8 @@ ThrowCompletionOr<Object*> DurationFormatConstructor::construct(FunctionObject& if (result.nu.has_value()) duration_format->set_numbering_system(result.nu.release_value()); - // 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long"). - auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv, "digital"sv }, "long"sv)); + // 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "short"). + auto style = TRY(get_option(vm, *options, vm.names.style, OptionType::String, { "long"sv, "short"sv, "narrow"sv, "digital"sv }, "short"sv)); // 14. Set durationFormat.[[Style]] to style. duration_format->set_style(style.as_string().string()); 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 a2b45f04a0..793654f669 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 @@ -17,10 +17,10 @@ describe("correct behavior", () => { nanoseconds: 9, }; expect(new Intl.DurationFormat().format(duration)).toBe( - "1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds, 8 microseconds, and 9 nanoseconds" + "1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, and 9 ns" ); expect(new Intl.DurationFormat("en").format(duration)).toBe( - "1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds, 8 microseconds, and 9 nanoseconds" + "1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, and 9 ns" ); expect(new Intl.DurationFormat("en", { style: "long" }).format(duration)).toBe( "1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds, 8 microseconds, and 9 nanoseconds" 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 45b553c715..a58c574f48 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 @@ -17,46 +17,46 @@ describe("correct behavior", () => { nanoseconds: 9, }; expect(new Intl.DurationFormat().formatToParts(duration)).toEqual([ - { type: "element", value: "1 year" }, + { type: "element", value: "1 yr" }, { type: "literal", value: ", " }, - { type: "element", value: "2 months" }, + { type: "element", value: "2 mths" }, { type: "literal", value: ", " }, - { type: "element", value: "3 weeks" }, + { type: "element", value: "3 wks" }, { type: "literal", value: ", " }, { type: "element", value: "3 days" }, { type: "literal", value: ", " }, - { type: "element", value: "4 hours" }, + { type: "element", value: "4 hr" }, { type: "literal", value: ", " }, - { type: "element", value: "5 minutes" }, + { type: "element", value: "5 min" }, { type: "literal", value: ", " }, - { type: "element", value: "6 seconds" }, + { type: "element", value: "6 sec" }, { type: "literal", value: ", " }, - { type: "element", value: "7 milliseconds" }, + { type: "element", value: "7 ms" }, { type: "literal", value: ", " }, - { type: "element", value: "8 microseconds" }, + { type: "element", value: "8 μs" }, { type: "literal", value: ", and " }, - { type: "element", value: "9 nanoseconds" }, + { type: "element", value: "9 ns" }, ]); expect(new Intl.DurationFormat("en").formatToParts(duration)).toEqual([ - { type: "element", value: "1 year" }, + { type: "element", value: "1 yr" }, { type: "literal", value: ", " }, - { type: "element", value: "2 months" }, + { type: "element", value: "2 mths" }, { type: "literal", value: ", " }, - { type: "element", value: "3 weeks" }, + { type: "element", value: "3 wks" }, { type: "literal", value: ", " }, { type: "element", value: "3 days" }, { type: "literal", value: ", " }, - { type: "element", value: "4 hours" }, + { type: "element", value: "4 hr" }, { type: "literal", value: ", " }, - { type: "element", value: "5 minutes" }, + { type: "element", value: "5 min" }, { type: "literal", value: ", " }, - { type: "element", value: "6 seconds" }, + { type: "element", value: "6 sec" }, { type: "literal", value: ", " }, - { type: "element", value: "7 milliseconds" }, + { type: "element", value: "7 ms" }, { type: "literal", value: ", " }, - { type: "element", value: "8 microseconds" }, + { type: "element", value: "8 μs" }, { type: "literal", value: ", and " }, - { type: "element", value: "9 nanoseconds" }, + { type: "element", value: "9 ns" }, ]); expect(new Intl.DurationFormat("en", { style: "long" }).formatToParts(duration)).toEqual([ { type: "element", value: "1 year" }, diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.resolvedOptions.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.resolvedOptions.js index 1ac210479f..e76ee54fa4 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.resolvedOptions.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.prototype.resolvedOptions.js @@ -56,7 +56,7 @@ describe("correct behavior", () => { test("style", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().style).toBe("long"); + expect(en1.resolvedOptions().style).toBe("short"); ["long", "short", "narrow", "digital"].forEach(style => { const en2 = new Intl.DurationFormat("en", { style: style }); @@ -66,7 +66,7 @@ describe("correct behavior", () => { test("years", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().years).toBe("long"); + expect(en1.resolvedOptions().years).toBe("short"); ["long", "short", "narrow"].forEach(years => { const en2 = new Intl.DurationFormat("en", { years: years }); @@ -86,7 +86,7 @@ describe("correct behavior", () => { test("months", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().months).toBe("long"); + expect(en1.resolvedOptions().months).toBe("short"); ["long", "short", "narrow"].forEach(months => { const en2 = new Intl.DurationFormat("en", { months: months }); @@ -106,7 +106,7 @@ describe("correct behavior", () => { test("weeks", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().weeks).toBe("long"); + expect(en1.resolvedOptions().weeks).toBe("short"); ["long", "short", "narrow"].forEach(weeks => { const en2 = new Intl.DurationFormat("en", { weeks: weeks }); @@ -126,7 +126,7 @@ describe("correct behavior", () => { test("days", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().days).toBe("long"); + expect(en1.resolvedOptions().days).toBe("short"); ["long", "short", "narrow"].forEach(days => { const en2 = new Intl.DurationFormat("en", { days: days }); @@ -146,7 +146,7 @@ describe("correct behavior", () => { test("hours", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().hours).toBe("long"); + expect(en1.resolvedOptions().hours).toBe("short"); ["long", "short", "narrow"].forEach(hours => { const en2 = new Intl.DurationFormat("en", { hours: hours }); @@ -170,7 +170,7 @@ describe("correct behavior", () => { test("minutes", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().minutes).toBe("long"); + expect(en1.resolvedOptions().minutes).toBe("short"); ["long", "short", "narrow"].forEach(minutes => { const en2 = new Intl.DurationFormat("en", { minutes: minutes }); @@ -194,7 +194,7 @@ describe("correct behavior", () => { test("seconds", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().seconds).toBe("long"); + expect(en1.resolvedOptions().seconds).toBe("short"); ["long", "short", "narrow"].forEach(seconds => { const en2 = new Intl.DurationFormat("en", { seconds: seconds }); @@ -218,7 +218,7 @@ describe("correct behavior", () => { test("milliseconds", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().milliseconds).toBe("long"); + expect(en1.resolvedOptions().milliseconds).toBe("short"); ["long", "short", "narrow"].forEach(milliseconds => { const en2 = new Intl.DurationFormat("en", { milliseconds: milliseconds }); @@ -240,7 +240,7 @@ describe("correct behavior", () => { test("microseconds", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().microseconds).toBe("long"); + expect(en1.resolvedOptions().microseconds).toBe("short"); ["long", "short", "narrow"].forEach(microseconds => { const en2 = new Intl.DurationFormat("en", { microseconds: microseconds }); @@ -262,7 +262,7 @@ describe("correct behavior", () => { test("nanoseconds", () => { const en1 = new Intl.DurationFormat("en"); - expect(en1.resolvedOptions().nanoseconds).toBe("long"); + expect(en1.resolvedOptions().nanoseconds).toBe("short"); ["long", "short", "narrow", "numeric"].forEach(nanoseconds => { const en2 = new Intl.DurationFormat("en", { nanoseconds: nanoseconds }); |