1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:37:45 +00:00

LibJS: Implement Date.prototype.getTimezoneOffset

This commit is contained in:
Timothy Flynn 2022-01-15 00:48:49 -05:00 committed by Linus Groh
parent 032664332b
commit 6576d0291c
2 changed files with 36 additions and 4 deletions

View file

@ -0,0 +1,30 @@
describe("errors", () => {
test("called on non-Date object", () => {
expect(() => {
Date.prototype.getTimezoneOffset();
}).toThrowWithMessage(TypeError, "Not an object of type Date");
});
});
describe("correct behavior", () => {
test("NaN", () => {
const d = new Date(NaN);
expect(d.getTimezoneOffset()).toBeNaN();
});
test("time clip", () => {
const d = new Date(-8.65e15);
expect(d.getTimezoneOffset()).toBeNaN();
});
test("basic functionality", () => {
// Exact return values from getTimezoneOffset depend on the time zone of the host machine.
// So we can't test exact values, but that value should not change here.
const d0 = new Date(Date.parse("1989-01-23T14:30-00:00"));
const d1 = new Date(Date.parse("1989-01-23T14:30-05:00"));
const offset0 = d0.getTimezoneOffset();
const offset1 = d1.getTimezoneOffset();
expect(offset0).toBe(offset1);
});
});