Skip to content

Build your personal knowledge base with Trilium Notes

fix(web-clipper): send the right offset for non-whole-hour time zones

Elian Doran1cd0407518b2
diff --git a/apps/web-clipper/entrypoints/background/trilium_server_facade.spec.ts b/apps/web-clipper/entrypoints/background/trilium_server_facade.spec.ts
index 072f3cbcd5..07c4e998f9 100644
--- a/apps/web-clipper/entrypoints/background/trilium_server_facade.spec.ts
+++ b/apps/web-clipper/entrypoints/background/trilium_server_facade.spec.ts
@@ -222,11 +222,20 @@ describe("TriliumServerFacade", () => {
const facade = await createFacade();
vi.setSystemTime(new Date("2026-03-04T10:20:30.456Z"));
- vi.spyOn(Date.prototype, "getTimezoneOffset").mockReturnValue(-120);
- expect(facade.localNowDateTime()).toBe("2026-03-04 12:20:30.456+02:00");
-
- vi.spyOn(Date.prototype, "getTimezoneOffset").mockReturnValue(300);
- expect(facade.localNowDateTime()).toBe("2026-03-04 05:20:30.456-05:00");
+ const offsets: [ number, string ][] = [
+ [ -120, "2026-03-04 12:20:30.456+02:00" ],
+ [ 300, "2026-03-04 05:20:30.456-05:00" ],
+ [ 0, "2026-03-04 10:20:30.456+00:00" ],
+ [ -330, "2026-03-04 15:50:30.456+05:30" ],
+ [ -345, "2026-03-04 16:05:30.456+05:45" ],
+ [ 210, "2026-03-04 06:50:30.456-03:30" ],
+ [ -630, "2026-03-04 20:50:30.456+10:30" ]
+ ];
+ const getTimezoneOffset = vi.spyOn(Date.prototype, "getTimezoneOffset");
+ for (const [ offset, expected ] of offsets) {
+ getTimezoneOffset.mockReturnValue(offset);
+ expect.soft(facade.localNowDateTime(), `offset ${offset}`).toBe(expected);
+ }
});
});
diff --git a/apps/web-clipper/entrypoints/background/trilium_server_facade.ts b/apps/web-clipper/entrypoints/background/trilium_server_facade.ts
index e9fd25df88..c73f0ae364 100644
--- a/apps/web-clipper/entrypoints/background/trilium_server_facade.ts
+++ b/apps/web-clipper/entrypoints/background/trilium_server_facade.ts
@@ -237,9 +237,12 @@ export default class TriliumServerFacade {
const date = new Date();
const off = date.getTimezoneOffset();
const absoff = Math.abs(off);
- return (`${new Date(date.getTime() - off * 60 * 1000).toISOString().substr(0,23).replace("T", " ") +
- (off > 0 ? '-' : '+') +
- (absoff / 60).toFixed(0).padStart(2,'0') }:${
- (absoff % 60).toString().padStart(2,'0')}`);
+ const localTime = new Date(date.getTime() - off * 60 * 1000).toISOString()
+ .substring(0, 23)
+ .replace("T", " ");
+ const sign = off > 0 ? "-" : "+";
+ const hours = String(Math.floor(absoff / 60)).padStart(2, "0");
+ const minutes = String(absoff % 60).padStart(2, "0");
+ return `${localTime}${sign}${hours}:${minutes}`;
}
}