Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(calendar): reproduce recurring events shifted by the UTC offset
Claudeca20545b363f
diff --git a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts b/apps/client/src/widgets/collections/calendar/event_builder.spec.tsindex da3f81fe95..2ae7559dc9 100644--- a/apps/client/src/widgets/collections/calendar/event_builder.spec.ts+++ b/apps/client/src/widgets/collections/calendar/event_builder.spec.ts@@ -1,9 +1,14 @@-import { describe, expect, it, vi } from "vitest";+import rrulePlugin from "@fullcalendar/rrule";+import { LOCALES } from "@triliumnext/commons";+import { Calendar, EventInput } from "fullcalendar";+import dayGridPlugin from "fullcalendar/daygrid";+import themePlugin from "fullcalendar/themes/forma";+import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";+import { buildNote, buildNotes } from "../../../test/easy-froca.js";import { buildEvent, buildEvents } from "./event_builder.js";import { LOCALE_MAPPINGS } from "./index.js";import { isValidDuration, parseDurationSeconds } from "./utils.js";-import { LOCALES } from "@triliumnext/commons";describe("Building events", () => {it("supports start date", async () => {@@ -389,8 +394,73 @@ describe("Recurrence", () => {expect(calledWithInvalid).toBe(true);consoleSpy.mockRestore();});++ describe("in a time zone ahead of UTC", () => {+ const originalTimeZone = process.env.TZ;++ beforeAll(() => {+ process.env.TZ = "Europe/Bucharest";+ });++ afterAll(() => {+ process.env.TZ = originalTimeZone;+ });++ it.each([+ [ "without an end date", "RRULE:FREQ=WEEKLY;BYDAY=SU" ],+ [ "with an end date", "RRULE:FREQ=WEEKLY;BYDAY=SU;UNTIL=20261130T235959Z" ]+ ])("shows each occurrence at the event's local time %s", async (_, recurrence) => {+ const noteIds = buildNotes([+ {+ title: "Weekly",+ "#startDate": "2026-10-04",+ "#startTime": "11:00",+ "#endTime": "13:00",+ "#recurrence": recurrence+ }+ ]);+ const events = await buildEvents(noteIds);++ const occurrences = renderOccurrences(events, "2026-10-01");+ expect(occurrences.map(({ start }) => start)).toEqual([+ "2026-10-04 11:00", "2026-10-11 11:00", "2026-10-18 11:00", "2026-10-25 11:00",+ "2026-11-01 11:00", "2026-11-08 11:00"+ ]);+ expect(occurrences.every(({ end }) => end.endsWith(" 13:00"))).toBe(true);+ });+ });});+/**+ * Expands `events` through FullCalendar and its rrule plugin, the way the calendar view does, and+ * returns the local start and end of each occurrence in the month view around `date`.+ */+function renderOccurrences(events: EventInput[], date: string) {+ const element = document.createElement("div");+ document.body.append(element);+ const calendar = new Calendar(element, {+ plugins: [ themePlugin, dayGridPlugin, rrulePlugin ],+ initialView: "dayGridMonth",+ initialDate: date,+ events+ });+ calendar.render();++ const occurrences = calendar.getEvents()+ .map(({ start, end }) => ({ start: formatLocal(start), end: formatLocal(end) }))+ .sort((a, b) => a.start.localeCompare(b.start));+ calendar.destroy();+ element.remove();+ return occurrences;+}++function formatLocal(date: Date | null) {+ if (!date) return "";+ const pad = (value: number) => String(value).padStart(2, "0");+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} `+ + `${pad(date.getHours())}:${pad(date.getMinutes())}`;+}+describe("isValidDuration", () => {it("accepts valid durations", () => {diff --git a/apps/client/vite.config.mts b/apps/client/vite.config.mtsindex fbe0b0c216..460a765301 100644--- a/apps/client/vite.config.mts+++ b/apps/client/vite.config.mts@@ -139,6 +139,13 @@ export default defineConfig(() => ({setupFiles: ["./src/test/setup.ts"],+ server: {+ deps: {+ // The plugin reads `rrule` through a namespace import, which Node resolves to the+ // package's CommonJS build with no named exports. Bundling it applies Vite's interop.+ inline: ["@fullcalendar/rrule"]+ }+ },reporters: ["verbose",["html", { outputFile: "./test-output/vitest/html/index.html" }],