LibJS: Begin implementing the relativeTo option of Duration.compare

This commit is contained in:
Timothy Flynn 2024-11-22 17:26:53 -05:00 committed by Andreas Kling
commit 0befd52725
Notes: github-actions[bot] 2024-11-23 13:47:08 +00:00
4 changed files with 55 additions and 3 deletions

View file

@ -27,6 +27,26 @@ describe("correct behavior", () => {
const duration2 = "P2D";
checkCommonResults(duration1, duration2);
});
test("relative to plain date", () => {
const oneMonth = new Temporal.Duration(0, 1);
const thirtyDays = new Temporal.Duration(0, 0, 0, 30);
let result = Temporal.Duration.compare(oneMonth, thirtyDays, {
relativeTo: Temporal.PlainDate.from("2018-04-01"),
});
expect(result).toBe(0);
result = Temporal.Duration.compare(oneMonth, thirtyDays, {
relativeTo: Temporal.PlainDate.from("2018-03-01"),
});
expect(result).toBe(1);
result = Temporal.Duration.compare(oneMonth, thirtyDays, {
relativeTo: Temporal.PlainDate.from("2018-02-01"),
});
expect(result).toBe(-1);
});
});
describe("errors", () => {