mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-25 18:58:56 +00:00
LibJS: Ensure GetDateTimeFormat returns nonnull for the best format
This is an editorial change in the Temporal proposal. See:
8a52801
This commit is contained in:
parent
7104d724ee
commit
234f218803
Notes:
github-actions[bot]
2024-12-06 16:13:59 +00:00
Author: https://github.com/trflynn89
Commit: 234f218803
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2813
5 changed files with 67 additions and 5 deletions
|
@ -75,6 +75,22 @@ describe("errors", () => {
|
|||
"Cannot format Temporal.ZonedDateTime, use Temporal.ZonedDateTime.prototype.toLocaleString"
|
||||
);
|
||||
});
|
||||
|
||||
test("Temporal fields must overlap formatter", () => {
|
||||
const yearFormatter = new Intl.DateTimeFormat([], { year: "numeric", calendar: "iso8601" });
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(1, 1);
|
||||
|
||||
const dayFormatter = new Intl.DateTimeFormat([], { day: "numeric", calendar: "iso8601" });
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(1972, 1);
|
||||
|
||||
expect(() => {
|
||||
yearFormatter.format(plainMonthDay);
|
||||
}).toThrowWithMessage(TypeError, "Unable to determine format for Temporal.PlainMonthDay");
|
||||
|
||||
expect(() => {
|
||||
dayFormatter.format(plainYearMonth);
|
||||
}).toThrowWithMessage(TypeError, "Unable to determine format for Temporal.PlainYearMonth");
|
||||
});
|
||||
});
|
||||
|
||||
const d0 = Date.UTC(2021, 11, 7, 17, 40, 50, 456);
|
||||
|
|
|
@ -112,6 +112,22 @@ describe("errors", () => {
|
|||
"Cannot format a date-time range with different date-time types"
|
||||
);
|
||||
});
|
||||
|
||||
test("Temporal fields must overlap formatter", () => {
|
||||
const yearFormatter = new Intl.DateTimeFormat([], { year: "numeric", calendar: "iso8601" });
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(1, 1);
|
||||
|
||||
const dayFormatter = new Intl.DateTimeFormat([], { day: "numeric", calendar: "iso8601" });
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(1972, 1);
|
||||
|
||||
expect(() => {
|
||||
yearFormatter.formatRange(plainMonthDay, plainMonthDay);
|
||||
}).toThrowWithMessage(TypeError, "Unable to determine format for Temporal.PlainMonthDay");
|
||||
|
||||
expect(() => {
|
||||
dayFormatter.formatRange(plainYearMonth, plainYearMonth);
|
||||
}).toThrowWithMessage(TypeError, "Unable to determine format for Temporal.PlainYearMonth");
|
||||
});
|
||||
});
|
||||
|
||||
const d0 = Date.UTC(1989, 0, 23, 7, 8, 9, 45);
|
||||
|
|
|
@ -112,6 +112,22 @@ describe("errors", () => {
|
|||
"Cannot format a date-time range with different date-time types"
|
||||
);
|
||||
});
|
||||
|
||||
test("Temporal fields must overlap formatter", () => {
|
||||
const yearFormatter = new Intl.DateTimeFormat([], { year: "numeric", calendar: "iso8601" });
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(1, 1);
|
||||
|
||||
const dayFormatter = new Intl.DateTimeFormat([], { day: "numeric", calendar: "iso8601" });
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(1972, 1);
|
||||
|
||||
expect(() => {
|
||||
yearFormatter.formatRangeToParts(plainMonthDay, plainMonthDay);
|
||||
}).toThrowWithMessage(TypeError, "Unable to determine format for Temporal.PlainMonthDay");
|
||||
|
||||
expect(() => {
|
||||
dayFormatter.formatRangeToParts(plainYearMonth, plainYearMonth);
|
||||
}).toThrowWithMessage(TypeError, "Unable to determine format for Temporal.PlainYearMonth");
|
||||
});
|
||||
});
|
||||
|
||||
const d0 = Date.UTC(1989, 0, 23, 7, 8, 9, 45);
|
||||
|
|
|
@ -71,6 +71,22 @@ describe("errors", () => {
|
|||
"Cannot format Temporal.ZonedDateTime, use Temporal.ZonedDateTime.prototype.toLocaleString"
|
||||
);
|
||||
});
|
||||
|
||||
test("Temporal fields must overlap formatter", () => {
|
||||
const yearFormatter = new Intl.DateTimeFormat([], { year: "numeric", calendar: "iso8601" });
|
||||
const plainMonthDay = new Temporal.PlainMonthDay(1, 1);
|
||||
|
||||
const dayFormatter = new Intl.DateTimeFormat([], { day: "numeric", calendar: "iso8601" });
|
||||
const plainYearMonth = new Temporal.PlainYearMonth(1972, 1);
|
||||
|
||||
expect(() => {
|
||||
yearFormatter.formatToParts(plainMonthDay);
|
||||
}).toThrowWithMessage(TypeError, "Unable to determine format for Temporal.PlainMonthDay");
|
||||
|
||||
expect(() => {
|
||||
dayFormatter.formatToParts(plainYearMonth);
|
||||
}).toThrowWithMessage(TypeError, "Unable to determine format for Temporal.PlainYearMonth");
|
||||
});
|
||||
});
|
||||
|
||||
const d = Date.UTC(1989, 0, 23, 7, 8, 9, 45);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue