LibJS: Implement the ECMA-402 ZonedDateTime.prototype.toLocaleString.js

This commit is contained in:
Timothy Flynn 2024-11-27 16:44:45 -05:00 committed by Andreas Kling
commit 0468463e2e
Notes: github-actions[bot] 2024-11-29 08:53:04 +00:00
2 changed files with 83 additions and 5 deletions

View file

@ -4,9 +4,20 @@ describe("correct behavior", () => {
});
test("basic functionality", () => {
const plainDateTime = new Temporal.PlainDateTime(2021, 11, 3, 1, 33, 5, 100, 200, 300);
const plainDateTime = new Temporal.PlainDateTime(
2021,
11,
3,
1,
33,
5,
100,
200,
300,
"gregory"
);
const zonedDateTime = plainDateTime.toZonedDateTime("UTC");
expect(zonedDateTime.toLocaleString()).toBe("2021-11-03T01:33:05.1002003+00:00[UTC]");
expect(zonedDateTime.toLocaleString()).toBe("11/3/2021, 1:33:5 AM UTC");
});
});
@ -16,4 +27,27 @@ describe("errors", () => {
Temporal.ZonedDateTime.prototype.toLocaleString.call("foo");
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.ZonedDateTime");
});
test("Temporal object must have same calendar", () => {
const plainDateTime = new Temporal.PlainDateTime(
2021,
11,
3,
1,
33,
5,
100,
200,
300,
"gregory"
);
const zonedDateTime = plainDateTime.toZonedDateTime("UTC");
expect(() => {
zonedDateTime.toLocaleString("en", { calendar: "iso8601" });
}).toThrowWithMessage(
RangeError,
"Cannot format Temporal.ZonedDateTime with calendar 'gregory' in locale with calendar 'iso8601'"
);
});
});