diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-08-30 11:42:02 -0400 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-08-30 14:26:11 -0400 |
commit | 127b28c940ea2fd4bbce2f94e6726801157684d1 (patch) | |
tree | d63451588d8e4f435ba0f5d831550d7fdd584d3b /Userland | |
parent | cab1cce522e2e795135b8e143a4653276c11f4d7 (diff) | |
download | serenity-127b28c940ea2fd4bbce2f94e6726801157684d1.zip |
LibJS: Use numeric style if the previous style was numeric or 2-digit
This is a normative change in the Intl.DurationFormat proposal. See:
https://github.com/tc39/proposal-intl-duration-format/commit/3a46ee3
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.js | 27 |
2 files changed, 33 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp index b76cc61beb..2bb1390a9f 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp @@ -252,7 +252,12 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, String // i. Set style to digitalBase. style = digital_base; } - // c. Else, + // c. Else if prevStyle is "numeric" or "2-digit", then + else if (previous_style == "numeric"sv || previous_style == "2-digit"sv) { + // i. Set style to "numeric". + style = "numeric"sv; + } + // d. Else, else { // i. Set style to baseStyle. style = base_style; diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.js index cc345f1423..97735be669 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/DurationFormat/DurationFormat.js @@ -267,6 +267,10 @@ describe("normal behavior", () => { }); ["numeric", "2-digit"].forEach(seconds => { expect(() => { + new Intl.DurationFormat("en", { hours: seconds }); + }).not.toThrow(); + + expect(() => { new Intl.DurationFormat("en", { style: "digital", hours: seconds }); }).not.toThrow(); }); @@ -288,6 +292,10 @@ describe("normal behavior", () => { }); ["numeric", "2-digit"].forEach(seconds => { expect(() => { + new Intl.DurationFormat("en", { minutes: seconds }); + }).not.toThrow(); + + expect(() => { new Intl.DurationFormat("en", { style: "digital", minutes: seconds }); }).not.toThrow(); }); @@ -309,6 +317,10 @@ describe("normal behavior", () => { }); ["numeric", "2-digit"].forEach(seconds => { expect(() => { + new Intl.DurationFormat("en", { seconds: seconds }); + }).not.toThrow(); + + expect(() => { new Intl.DurationFormat("en", { style: "digital", seconds: seconds }); }).not.toThrow(); }); @@ -328,6 +340,11 @@ describe("normal behavior", () => { new Intl.DurationFormat("en", { milliseconds: milliseconds }); }).not.toThrow(); }); + + expect(() => { + new Intl.DurationFormat("en", { milliseconds: "numeric" }); + }).not.toThrow(); + expect(() => { new Intl.DurationFormat("en", { style: "digital", milliseconds: "numeric" }); }).not.toThrow(); @@ -347,6 +364,11 @@ describe("normal behavior", () => { new Intl.DurationFormat("en", { microseconds: microseconds }); }).not.toThrow(); }); + + expect(() => { + new Intl.DurationFormat("en", { microseconds: "numeric" }); + }).not.toThrow(); + expect(() => { new Intl.DurationFormat("en", { style: "digital", microseconds: "numeric" }); }).not.toThrow(); @@ -366,6 +388,11 @@ describe("normal behavior", () => { new Intl.DurationFormat("en", { nanoseconds: nanoseconds }); }).not.toThrow(); }); + + expect(() => { + new Intl.DurationFormat("en", { nanoseconds: "numeric" }); + }).not.toThrow(); + expect(() => { new Intl.DurationFormat("en", { style: "digital", nanoseconds: "numeric" }); }).not.toThrow(); |