From a9ba4de0d046c18a68c6ec273ad513c6fa3b82a7 Mon Sep 17 00:00:00 2001 From: Donald Silveira Date: Tue, 29 Sep 2026 21:05:52 -0300 Subject: [PATCH] fix(web): show automation schedules in the server time zone - Include each server's schedule time zone in automation snapshots - Use it for next-run labels and explain missed-run behavior --- .../src/automation/AutomationService.test.ts | 5 +++ .../src/automation/AutomationService.ts | 6 ++- .../automations/AutomationsPage.tsx | 37 ++++++++++++++++--- apps/web/src/state/automations.ts | 6 ++- packages/contracts/src/automation.ts | 2 + 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/apps/server/src/automation/AutomationService.test.ts b/apps/server/src/automation/AutomationService.test.ts index e5d5aea62d8f0..529b29e82d18b 100644 --- a/apps/server/src/automation/AutomationService.test.ts +++ b/apps/server/src/automation/AutomationService.test.ts @@ -192,6 +192,11 @@ describe("AutomationService", () => { Option.map(snapshot, (value) => value.automations.map((entry) => entry.name)), Option.some(["Weekly review"]), ); + // Clients show schedule times in the zone the server evaluates them in. + assert.deepStrictEqual( + Option.map(snapshot, (value) => value.timeZone), + Option.some(Intl.DateTimeFormat().resolvedOptions().timeZone), + ); }), ), ); diff --git a/apps/server/src/automation/AutomationService.ts b/apps/server/src/automation/AutomationService.ts index d4cbb008238e1..ad74b201daf04 100644 --- a/apps/server/src/automation/AutomationService.ts +++ b/apps/server/src/automation/AutomationService.ts @@ -128,7 +128,11 @@ function toPublic(stored: StoredAutomation): Automation { } function toSnapshot(file: AutomationsFile): AutomationsSnapshot { - return { automations: file.automations.map(toPublic) }; + return { + automations: file.automations.map(toPublic), + // Schedules run in the host's local zone, which is what `latestTriggerAt` defaults to. + timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, + }; } function githubItemMatches(event: AutomationGitHubEvent, item: GitHubItem): boolean { diff --git a/apps/web/src/components/automations/AutomationsPage.tsx b/apps/web/src/components/automations/AutomationsPage.tsx index 023375a6007ea..5d76191749766 100644 --- a/apps/web/src/components/automations/AutomationsPage.tsx +++ b/apps/web/src/components/automations/AutomationsPage.tsx @@ -521,6 +521,7 @@ function AutomationEditor({ const primaryEnvironmentId = usePrimaryEnvironmentId(); const connectedEnvironments = useConnectedEnvironments(); const projects = useProjects(); + const { timeZones } = useAutomations(); // A new draft runs on this device's server until the user picks another environment. const environmentId = draft.environmentId ?? @@ -528,6 +529,7 @@ function AutomationEditor({ ?.environmentId ?? connectedEnvironments[0]?.environmentId ?? null; + const timeZone = environmentId ? timeZones.get(environmentId) : undefined; const patch = (next: Partial) => setDraft((current) => ({ ...current, ...next })); @@ -702,6 +704,7 @@ function AutomationEditor({ // oxlint-disable-next-line react/no-array-index-key -- triggers have no identity of their own key={index} trigger={trigger} + timeZone={timeZone} onChange={(next) => patch({ triggers: draft.triggers.map((entry, i) => (i === index ? next : entry)), @@ -716,6 +719,13 @@ function AutomationEditor({

Without a trigger, the automation only runs when you press Run now.

+ ) : draft.triggers.some((trigger) => trigger.type !== "github") ? ( +

+ {timeZone ? `Times use ${timeZone}. ` : null} + {draft.catchUpMinutes === 0 + ? "Missed runs are skipped." + : `Missed runs are skipped after ${formatCatchUpWindow(draft.catchUpMinutes)}.`} +

) : null} @@ -897,6 +907,11 @@ function OptionSelect({ ); } +function formatCatchUpWindow(minutes: number): string { + if (minutes % 60 === 0) return minutes === 60 ? "1 hour" : `${minutes / 60} hours`; + return minutes === 1 ? "1 minute" : `${minutes} minutes`; +} + const CADENCE_LABELS: Record = { hourly: "Hourly", daily: "Daily", @@ -911,10 +926,12 @@ const MINUTE_OPTIONS = Array.from({ length: 12 }, (_, index) => { function TriggerRow({ trigger, + timeZone, onChange, onRemove, }: { trigger: AutomationTrigger; + timeZone: string | undefined; onChange: (trigger: AutomationTrigger) => void; onRemove: () => void; }) { @@ -927,7 +944,7 @@ function TriggerRow({ on the project's GitHub repository ) : trigger.type === "cron" ? ( - + ) : ( <> )} - + )}