1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:17:44 +00:00

LibJS: Implement Temporal.TimeZone.prototype.getInstantFor()

This commit is contained in:
Linus Groh 2021-11-01 14:20:06 +01:00
parent 55e1edd51b
commit 97f6c6029f
15 changed files with 341 additions and 0 deletions

View file

@ -0,0 +1,29 @@
describe("correct behavior", () => {
test("length is 1", () => {
expect(Temporal.TimeZone.prototype.getInstantFor).toHaveLength(1);
});
test("basic functionality", () => {
const timeZone = new Temporal.TimeZone("UTC");
const plainDateTime = new Temporal.PlainDateTime(2021, 7, 6, 18, 14, 47);
const instant = timeZone.getInstantFor(plainDateTime);
expect(instant).toBeInstanceOf(Temporal.Instant);
expect(instant.epochNanoseconds).toBe(1625595287000000000n);
});
test("custom offset", () => {
const timeZone = new Temporal.TimeZone("+01:30");
const plainDateTime = new Temporal.PlainDateTime(2021, 7, 6, 18, 14, 47);
const instant = timeZone.getInstantFor(plainDateTime);
expect(instant).toBeInstanceOf(Temporal.Instant);
expect(instant.epochNanoseconds).toBe(1625589887000000000n);
});
});
describe("errors", () => {
test("this value must be a Temporal.TimeZone object", () => {
expect(() => {
Temporal.TimeZone.prototype.getInstantFor.call("foo");
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.TimeZone");
});
});