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

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

This commit is contained in:
Linus Groh 2021-10-30 10:22:19 +02:00
parent 82792a6815
commit 5fde02184d
6 changed files with 92 additions and 0 deletions

View file

@ -0,0 +1,31 @@
describe("correct behavior", () => {
test("length is 1", () => {
expect(Temporal.TimeZone.prototype.getPossibleInstantsFor).toHaveLength(1);
});
test("basic functionality", () => {
const timeZone = new Temporal.TimeZone("UTC");
const plainDateTime = new Temporal.PlainDateTime(2021, 7, 6, 18, 14, 47);
const possibleInstants = timeZone.getPossibleInstantsFor(plainDateTime);
expect(possibleInstants).toBeInstanceOf(Array);
expect(possibleInstants).toHaveLength(1);
expect(possibleInstants[0].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 possibleInstants = timeZone.getPossibleInstantsFor(plainDateTime);
expect(possibleInstants).toBeInstanceOf(Array);
expect(possibleInstants).toHaveLength(1);
expect(possibleInstants[0].epochNanoseconds).toBe(1625589887000000000n);
});
});
describe("errors", () => {
test("this value must be a Temporal.TimeZone object", () => {
expect(() => {
Temporal.TimeZone.prototype.getPossibleInstantsFor.call("foo");
}).toThrowWithMessage(TypeError, "Not an object of type Temporal.TimeZone");
});
});