mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:17:35 +00:00
LibJS: Create DurationFormat's ListFormat object with type and style
This is a normative change in the Intl.DurationFormat spec. See:
1304e4b
This commit is contained in:
parent
127b28c940
commit
c477425b9b
4 changed files with 57 additions and 36 deletions
|
@ -17,22 +17,22 @@ describe("correct behavior", () => {
|
|||
nanoseconds: 9,
|
||||
};
|
||||
expect(new Intl.DurationFormat().format(duration)).toBe(
|
||||
"1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, and 9 ns"
|
||||
"1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns"
|
||||
);
|
||||
expect(new Intl.DurationFormat("en").format(duration)).toBe(
|
||||
"1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, and 9 ns"
|
||||
"1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 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"
|
||||
"1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds, 8 microseconds, 9 nanoseconds"
|
||||
);
|
||||
expect(new Intl.DurationFormat("en", { style: "short" }).format(duration)).toBe(
|
||||
"1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, and 9 ns"
|
||||
"1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns"
|
||||
);
|
||||
expect(new Intl.DurationFormat("en", { style: "narrow" }).format(duration)).toBe(
|
||||
"1y, 2m, 3w, 3d, 4h, 5m, 6s, 7ms, 8μs, and 9ns"
|
||||
"1y 2m 3w 3d 4h 5m 6s 7ms 8μs 9ns"
|
||||
);
|
||||
expect(new Intl.DurationFormat("en", { style: "digital" }).format(duration)).toBe(
|
||||
"1y, 2m, 3w, 3d, and 4:05:06"
|
||||
"1y 2m 3w 3d 4:05:06"
|
||||
);
|
||||
expect(
|
||||
new Intl.DurationFormat("en", {
|
||||
|
@ -40,7 +40,7 @@ describe("correct behavior", () => {
|
|||
nanoseconds: "numeric",
|
||||
fractionalDigits: 3,
|
||||
}).format(duration)
|
||||
).toBe("1y, 2m, 3w, 3d, 4h, 5m, 6s, 7ms, and 8.009μs");
|
||||
).toBe("1y 2m 3w 3d 4h 5m 6s 7ms 8.009μs");
|
||||
|
||||
expect(new Intl.DurationFormat("de", { style: "long" }).format(duration)).toBe(
|
||||
"1 Jahr, 2 Monate, 3 Wochen, 3 Tage, 4 Stunden, 5 Minuten, 6 Sekunden, 7 Millisekunden, 8 Mikrosekunden und 9 Nanosekunden"
|
||||
|
|
|
@ -34,7 +34,7 @@ describe("correct behavior", () => {
|
|||
{ type: "element", value: "7 ms" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "element", value: "8 μs" },
|
||||
{ type: "literal", value: ", and " },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "element", value: "9 ns" },
|
||||
]);
|
||||
expect(new Intl.DurationFormat("en").formatToParts(duration)).toEqual([
|
||||
|
@ -55,7 +55,7 @@ describe("correct behavior", () => {
|
|||
{ type: "element", value: "7 ms" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "element", value: "8 μs" },
|
||||
{ type: "literal", value: ", and " },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "element", value: "9 ns" },
|
||||
]);
|
||||
expect(new Intl.DurationFormat("en", { style: "long" }).formatToParts(duration)).toEqual([
|
||||
|
@ -76,7 +76,7 @@ describe("correct behavior", () => {
|
|||
{ type: "element", value: "7 milliseconds" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "element", value: "8 microseconds" },
|
||||
{ type: "literal", value: ", and " },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "element", value: "9 nanoseconds" },
|
||||
]);
|
||||
expect(new Intl.DurationFormat("en", { style: "short" }).formatToParts(duration)).toEqual([
|
||||
|
@ -97,40 +97,40 @@ describe("correct behavior", () => {
|
|||
{ type: "element", value: "7 ms" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "element", value: "8 μs" },
|
||||
{ type: "literal", value: ", and " },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "element", value: "9 ns" },
|
||||
]);
|
||||
expect(new Intl.DurationFormat("en", { style: "narrow" }).formatToParts(duration)).toEqual([
|
||||
{ type: "element", value: "1y" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "2m" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "3w" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "3d" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "4h" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "5m" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "6s" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "7ms" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "8μs" },
|
||||
{ type: "literal", value: ", and " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "9ns" },
|
||||
]);
|
||||
expect(new Intl.DurationFormat("en", { style: "digital" }).formatToParts(duration)).toEqual(
|
||||
[
|
||||
{ type: "element", value: "1y" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "2m" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "3w" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "3d" },
|
||||
{ type: "literal", value: ", and " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "4:05:06" },
|
||||
]
|
||||
);
|
||||
|
@ -142,21 +142,21 @@ describe("correct behavior", () => {
|
|||
}).formatToParts(duration)
|
||||
).toEqual([
|
||||
{ type: "element", value: "1y" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "2m" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "3w" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "3d" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "4h" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "5m" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "6s" },
|
||||
{ type: "literal", value: ", " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "7ms" },
|
||||
{ type: "literal", value: ", and " },
|
||||
{ type: "literal", value: " " },
|
||||
{ type: "element", value: "8.009μs" },
|
||||
]);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue