1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:27:36 +00:00

LibJS: Default to "short" for DurationFormat's style option

This is a normative change in the Intl.DurationFormat proposal. See:
b289494
This commit is contained in:
Timothy Flynn 2022-08-30 10:23:38 -04:00 committed by Tim Flynn
parent 765d016670
commit d57b92da09
4 changed files with 33 additions and 33 deletions

View file

@ -89,8 +89,8 @@ ThrowCompletionOr<Object*> DurationFormatConstructor::construct(FunctionObject&
if (result.nu.has_value()) if (result.nu.has_value())
duration_format->set_numbering_system(result.nu.release_value()); duration_format->set_numbering_system(result.nu.release_value());
// 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long"). // 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 }, "long"sv)); 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. // 14. Set durationFormat.[[Style]] to style.
duration_format->set_style(style.as_string().string()); duration_format->set_style(style.as_string().string());

View file

@ -17,10 +17,10 @@ describe("correct behavior", () => {
nanoseconds: 9, nanoseconds: 9,
}; };
expect(new Intl.DurationFormat().format(duration)).toBe( 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( 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( 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" "1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds, 8 microseconds, and 9 nanoseconds"

View file

@ -17,46 +17,46 @@ describe("correct behavior", () => {
nanoseconds: 9, nanoseconds: 9,
}; };
expect(new Intl.DurationFormat().formatToParts(duration)).toEqual([ expect(new Intl.DurationFormat().formatToParts(duration)).toEqual([
{ type: "element", value: "1 year" }, { type: "element", value: "1 yr" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "2 months" }, { type: "element", value: "2 mths" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "3 weeks" }, { type: "element", value: "3 wks" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "3 days" }, { type: "element", value: "3 days" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "4 hours" }, { type: "element", value: "4 hr" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "5 minutes" }, { type: "element", value: "5 min" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "6 seconds" }, { type: "element", value: "6 sec" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "7 milliseconds" }, { type: "element", value: "7 ms" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "8 microseconds" }, { type: "element", value: "8 μs" },
{ type: "literal", value: ", and " }, { type: "literal", value: ", and " },
{ type: "element", value: "9 nanoseconds" }, { type: "element", value: "9 ns" },
]); ]);
expect(new Intl.DurationFormat("en").formatToParts(duration)).toEqual([ expect(new Intl.DurationFormat("en").formatToParts(duration)).toEqual([
{ type: "element", value: "1 year" }, { type: "element", value: "1 yr" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "2 months" }, { type: "element", value: "2 mths" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "3 weeks" }, { type: "element", value: "3 wks" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "3 days" }, { type: "element", value: "3 days" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "4 hours" }, { type: "element", value: "4 hr" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "5 minutes" }, { type: "element", value: "5 min" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "6 seconds" }, { type: "element", value: "6 sec" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "7 milliseconds" }, { type: "element", value: "7 ms" },
{ type: "literal", value: ", " }, { type: "literal", value: ", " },
{ type: "element", value: "8 microseconds" }, { type: "element", value: "8 μs" },
{ type: "literal", value: ", and " }, { type: "literal", value: ", and " },
{ type: "element", value: "9 nanoseconds" }, { type: "element", value: "9 ns" },
]); ]);
expect(new Intl.DurationFormat("en", { style: "long" }).formatToParts(duration)).toEqual([ expect(new Intl.DurationFormat("en", { style: "long" }).formatToParts(duration)).toEqual([
{ type: "element", value: "1 year" }, { type: "element", value: "1 year" },

View file

@ -56,7 +56,7 @@ describe("correct behavior", () => {
test("style", () => { test("style", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().style).toBe("long"); expect(en1.resolvedOptions().style).toBe("short");
["long", "short", "narrow", "digital"].forEach(style => { ["long", "short", "narrow", "digital"].forEach(style => {
const en2 = new Intl.DurationFormat("en", { style: style }); const en2 = new Intl.DurationFormat("en", { style: style });
@ -66,7 +66,7 @@ describe("correct behavior", () => {
test("years", () => { test("years", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().years).toBe("long"); expect(en1.resolvedOptions().years).toBe("short");
["long", "short", "narrow"].forEach(years => { ["long", "short", "narrow"].forEach(years => {
const en2 = new Intl.DurationFormat("en", { years: years }); const en2 = new Intl.DurationFormat("en", { years: years });
@ -86,7 +86,7 @@ describe("correct behavior", () => {
test("months", () => { test("months", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().months).toBe("long"); expect(en1.resolvedOptions().months).toBe("short");
["long", "short", "narrow"].forEach(months => { ["long", "short", "narrow"].forEach(months => {
const en2 = new Intl.DurationFormat("en", { months: months }); const en2 = new Intl.DurationFormat("en", { months: months });
@ -106,7 +106,7 @@ describe("correct behavior", () => {
test("weeks", () => { test("weeks", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().weeks).toBe("long"); expect(en1.resolvedOptions().weeks).toBe("short");
["long", "short", "narrow"].forEach(weeks => { ["long", "short", "narrow"].forEach(weeks => {
const en2 = new Intl.DurationFormat("en", { weeks: weeks }); const en2 = new Intl.DurationFormat("en", { weeks: weeks });
@ -126,7 +126,7 @@ describe("correct behavior", () => {
test("days", () => { test("days", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().days).toBe("long"); expect(en1.resolvedOptions().days).toBe("short");
["long", "short", "narrow"].forEach(days => { ["long", "short", "narrow"].forEach(days => {
const en2 = new Intl.DurationFormat("en", { days: days }); const en2 = new Intl.DurationFormat("en", { days: days });
@ -146,7 +146,7 @@ describe("correct behavior", () => {
test("hours", () => { test("hours", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().hours).toBe("long"); expect(en1.resolvedOptions().hours).toBe("short");
["long", "short", "narrow"].forEach(hours => { ["long", "short", "narrow"].forEach(hours => {
const en2 = new Intl.DurationFormat("en", { hours: hours }); const en2 = new Intl.DurationFormat("en", { hours: hours });
@ -170,7 +170,7 @@ describe("correct behavior", () => {
test("minutes", () => { test("minutes", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().minutes).toBe("long"); expect(en1.resolvedOptions().minutes).toBe("short");
["long", "short", "narrow"].forEach(minutes => { ["long", "short", "narrow"].forEach(minutes => {
const en2 = new Intl.DurationFormat("en", { minutes: minutes }); const en2 = new Intl.DurationFormat("en", { minutes: minutes });
@ -194,7 +194,7 @@ describe("correct behavior", () => {
test("seconds", () => { test("seconds", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().seconds).toBe("long"); expect(en1.resolvedOptions().seconds).toBe("short");
["long", "short", "narrow"].forEach(seconds => { ["long", "short", "narrow"].forEach(seconds => {
const en2 = new Intl.DurationFormat("en", { seconds: seconds }); const en2 = new Intl.DurationFormat("en", { seconds: seconds });
@ -218,7 +218,7 @@ describe("correct behavior", () => {
test("milliseconds", () => { test("milliseconds", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().milliseconds).toBe("long"); expect(en1.resolvedOptions().milliseconds).toBe("short");
["long", "short", "narrow"].forEach(milliseconds => { ["long", "short", "narrow"].forEach(milliseconds => {
const en2 = new Intl.DurationFormat("en", { milliseconds: milliseconds }); const en2 = new Intl.DurationFormat("en", { milliseconds: milliseconds });
@ -240,7 +240,7 @@ describe("correct behavior", () => {
test("microseconds", () => { test("microseconds", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().microseconds).toBe("long"); expect(en1.resolvedOptions().microseconds).toBe("short");
["long", "short", "narrow"].forEach(microseconds => { ["long", "short", "narrow"].forEach(microseconds => {
const en2 = new Intl.DurationFormat("en", { microseconds: microseconds }); const en2 = new Intl.DurationFormat("en", { microseconds: microseconds });
@ -262,7 +262,7 @@ describe("correct behavior", () => {
test("nanoseconds", () => { test("nanoseconds", () => {
const en1 = new Intl.DurationFormat("en"); const en1 = new Intl.DurationFormat("en");
expect(en1.resolvedOptions().nanoseconds).toBe("long"); expect(en1.resolvedOptions().nanoseconds).toBe("short");
["long", "short", "narrow", "numeric"].forEach(nanoseconds => { ["long", "short", "narrow", "numeric"].forEach(nanoseconds => {
const en2 = new Intl.DurationFormat("en", { nanoseconds: nanoseconds }); const en2 = new Intl.DurationFormat("en", { nanoseconds: nanoseconds });