LibJS: Require strict matching with a precise ZonedDateTime offset

This is a normative change in the Temporal proposal. See:
1117eaf
This commit is contained in:
Timothy Flynn 2025-06-02 10:13:05 -04:00 committed by Shannon Booth
commit c8b4dc4847
Notes: github-actions[bot] 2025-06-02 21:10:33 +00:00
3 changed files with 70 additions and 6 deletions

View file

@ -67,6 +67,21 @@ describe("correct behavior", () => {
});
expect(result).toBe(-1);
});
test("sub-minute time zone offset", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 31);
const duration2 = new Temporal.Duration(0, 1);
let result = Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1970-01-01T00:00:00-00:45[Africa/Monrovia]",
});
expect(result).toBe(0);
result = Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1970-01-01T00:00:00-00:44:30[Africa/Monrovia]",
});
expect(result).toBe(0);
});
});
describe("errors", () => {
@ -132,4 +147,27 @@ describe("errors", () => {
"A starting point is required for comparing calendar units"
);
});
test("sub-minute time zone offset mismatch", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 31);
const duration2 = new Temporal.Duration(0, 1);
expect(() => {
Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1970-01-01T00:00:00-00:44:40[Africa/Monrovia]",
});
}).toThrowWithMessage(
RangeError,
"Invalid offset for the provided date and time in the current time zone"
);
expect(() => {
Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1970-01-01T00:00:00-00:45:00[Africa/Monrovia]",
});
}).toThrowWithMessage(
RangeError,
"Invalid offset for the provided date and time in the current time zone"
);
});
});