mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-28 13:18:19 +00:00
LibJS: Implement the Temporal.Duration relative-to ZonedDateTime options
This commit is contained in:
parent
3e6133cc09
commit
18f95434bc
Notes:
github-actions[bot]
2024-11-26 10:04:10 +00:00
Author: https://github.com/trflynn89
Commit: 18f95434bc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2577
Reviewed-by: https://github.com/shannonbooth ✅
9 changed files with 296 additions and 35 deletions
|
@ -47,6 +47,26 @@ describe("correct behavior", () => {
|
|||
});
|
||||
expect(result).toBe(-1);
|
||||
});
|
||||
|
||||
test("relative to zoned date time", () => {
|
||||
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.ZonedDateTime.from("2018-04-01[UTC]"),
|
||||
});
|
||||
expect(result).toBe(0);
|
||||
|
||||
result = Temporal.Duration.compare(oneMonth, thirtyDays, {
|
||||
relativeTo: Temporal.ZonedDateTime.from("2018-03-01[UTC]"),
|
||||
});
|
||||
expect(result).toBe(1);
|
||||
|
||||
result = Temporal.Duration.compare(oneMonth, thirtyDays, {
|
||||
relativeTo: Temporal.ZonedDateTime.from("2018-02-01[UTC]"),
|
||||
});
|
||||
expect(result).toBe(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
|
|
|
@ -98,6 +98,20 @@ describe("correct behavior", () => {
|
|||
expect(result.months).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
test("relative to zoned date time", () => {
|
||||
const duration = new Temporal.Duration(0, 0, 0, 31);
|
||||
|
||||
[
|
||||
"2000-01-01[UTC]",
|
||||
"2000-01-01T00:00[UTC]",
|
||||
"2000-01-01T00:00+00:00[UTC]",
|
||||
"2000-01-01T00:00+00:00[UTC][u-ca=iso8601]",
|
||||
].forEach(relativeTo => {
|
||||
const result = duration.round({ largestUnit: "months", relativeTo });
|
||||
expect(result.months).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
|
|
|
@ -25,6 +25,20 @@ describe("correct behavior", () => {
|
|||
expect(result).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
test("relative to zoned date time", () => {
|
||||
const duration = new Temporal.Duration(0, 0, 0, 31);
|
||||
|
||||
[
|
||||
"2000-01-01[UTC]",
|
||||
"2000-01-01T00:00[UTC]",
|
||||
"2000-01-01T00:00+00:00[UTC]",
|
||||
"2000-01-01T00:00+00:00[UTC][u-ca=iso8601]",
|
||||
].forEach(relativeTo => {
|
||||
const result = duration.total({ unit: "months", relativeTo });
|
||||
expect(result).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue