Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(routines): search past skipped daylight-saving windows
Afloatec48552c74d1
diff --git a/server/routine-interval-gap.test.ts b/server/routine-interval-gap.test.tsnew file mode 100644index 0000000000..a533aceaca--- /dev/null+++ b/server/routine-interval-gap.test.ts@@ -0,0 +1,31 @@+import { afterEach, beforeEach, expect, it, vi } from "vitest";+import { latestIntervalOccurrence } from "./routine-intervals.ts";+import { cleanSchedule, nextOccurrence, type RoutineIntervalSchedule } from "./routine-schedules.ts";++beforeEach(() => { vi.stubEnv("TZ", "America/New_York"); });+afterEach(() => { vi.unstubAllEnvs(); });++function schedule(endsAt?: number): RoutineIntervalSchedule {+ return cleanSchedule({+ type: "interval", everyMinutes: 60, anchorAt: Date.parse("2026-03-01T00:00:00-05:00"),+ weekdays: [0], window: { start: "02:00", end: "03:00" }, ...(endsAt === undefined ? {} : { endsAt }),+ }, Date.parse("2026-03-01T00:00:00-05:00")) as RoutineIntervalSchedule;+}++it("finds the next allowed Sunday after the spring-forward week has no allowed hour", () => {+ expect(nextOccurrence(schedule(), Date.parse("2026-03-01T02:00:00-05:00")))+ .toBe(Date.parse("2026-03-15T02:00:00-04:00"));+});++it("finds the latest allowed occurrence across the missing-hour week", () => {+ expect(latestIntervalOccurrence(schedule(), Date.parse("2026-03-14T12:00:00-04:00")))+ .toBe(Date.parse("2026-03-01T02:00:00-05:00"));+});++it("keeps the end restriction and the ordinary weekly cadence", () => {+ expect(nextOccurrence(schedule(Date.parse("2026-03-14T23:59:00-04:00")), Date.parse("2026-03-01T02:00:00-05:00"))).toBeNull();+ expect(nextOccurrence(schedule(), Date.parse("2026-03-15T02:00:00-04:00")))+ .toBe(Date.parse("2026-03-22T02:00:00-04:00"));+ expect(latestIntervalOccurrence(schedule(), Date.parse("2026-03-22T02:00:00-04:00")))+ .toBe(Date.parse("2026-03-22T02:00:00-04:00"));+});diff --git a/server/routine-intervals.ts b/server/routine-intervals.tsindex 5cb1699633..76d60bdcb2 100644--- a/server/routine-intervals.ts+++ b/server/routine-intervals.ts@@ -4,7 +4,9 @@ import type { RoutineIntervalSchedule } from "./routine-schedules.ts";export const MAX_DATE_MS = 8_640_000_000_000_000;const LOCAL_DAY_MS = 24 * 60 * 60_000;-export const INTERVAL_RESTRICTION_SEARCH_MS = 9 * LOCAL_DAY_MS;+// A weekly window can disappear entirely in a spring-forward gap. Search past that skipped week,+// with room for the timezone transition and the aligned interval on either side.+export const INTERVAL_RESTRICTION_SEARCH_MS = 16 * LOCAL_DAY_MS;const CLOCK_TIME = /^([01]\d|2[0-3]):([0-5]\d)$/;export function clockMinutes(value: string): number | null {