mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-06 01:26:22 +00:00
LibJS: Implement the ECMA-402 ZonedDateTime.prototype.toLocaleString.js
This commit is contained in:
parent
c96f6c396f
commit
0468463e2e
Notes:
github-actions[bot]
2024-11-29 08:53:04 +00:00
Author: https://github.com/trflynn89
Commit: 0468463e2e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2615
2 changed files with 83 additions and 5 deletions
|
@ -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'"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue