1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibJS+LibUnicode: Support ambiguous time zone transitions

For example, time zone transitions can result in repeated or skipped
wall times. Temporal wants us to handle these transitions.
This commit is contained in:
Timothy Flynn 2025-06-02 11:04:29 -04:00 committed by Shannon Booth
parent c8b4dc4847
commit 8145572180
Notes: github-actions[bot] 2025-06-02 21:10:26 +00:00
4 changed files with 92 additions and 12 deletions

View file

@ -68,7 +68,7 @@ describe("correct behavior", () => {
expect(result).toBe(-1);
});
test("sub-minute time zone offset", () => {
test("sub-minute time zone offset (unambiguous time zone transition)", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 31);
const duration2 = new Temporal.Duration(0, 1);
@ -82,6 +82,26 @@ describe("correct behavior", () => {
});
expect(result).toBe(0);
});
test("sub-minute time zone offset (ambiguous time zone transition)", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 0, 24);
const duration2 = new Temporal.Duration(0, 0, 0, 1);
let result = Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1952-10-15T23:59:59-11:19:40[Pacific/Niue]",
});
expect(result).toBe(-1);
result = Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1952-10-15T23:59:59-11:20[Pacific/Niue]",
});
expect(result).toBe(-1);
result = Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1952-10-15T23:59:59-11:20:00[Pacific/Niue]",
});
expect(result).toBe(0);
});
});
describe("errors", () => {
@ -148,7 +168,7 @@ describe("errors", () => {
);
});
test("sub-minute time zone offset mismatch", () => {
test("sub-minute time zone offset mismatch (unambiguous time zone transition)", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 31);
const duration2 = new Temporal.Duration(0, 1);
@ -170,4 +190,18 @@ describe("errors", () => {
"Invalid offset for the provided date and time in the current time zone"
);
});
test("sub-minute time zone offset mismatch (ambiguous time zone transition)", () => {
const duration1 = new Temporal.Duration(0, 0, 0, 0, 24);
const duration2 = new Temporal.Duration(0, 0, 0, 1);
expect(() => {
Temporal.Duration.compare(duration1, duration2, {
relativeTo: "1952-10-15T23:59:59-11:19:50[Pacific/Niue]",
});
}).toThrowWithMessage(
RangeError,
"Invalid offset for the provided date and time in the current time zone"
);
});
});