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:
Timothy Flynn 2024-12-06 09:03:34 -05:00 committed by Tim Flynn
commit 234f218803
Notes: github-actions[bot] 2024-12-06 16:13:59 +00:00
5 changed files with 67 additions and 5 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);