Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix: timezone-safe date navigation, keep frames visible during day change

Louis Beaumontf98d6029c046
diff --git a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-controls.tsx b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-controls.tsx
index 59c9cfca6..daf8da2e7 100644
--- a/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-controls.tsx
+++ b/apps/screenpipe-app-tauri/components/rewind/timeline/timeline-controls.tsx
@@ -7,7 +7,6 @@
import { Button } from "@/components/ui/button";
import { ChevronLeft, ChevronRight, RefreshCw, CalendarIcon, Search, Play, Pause, Loader2 } from "lucide-react";
import {
- endOfDay,
format,
isAfter,
isSameDay,
@@ -139,13 +138,15 @@ export function TimelineControls({
);
const jumpDay = async (days: number) => {
- const today = new Date();
+ const today = startOfDay(new Date());
- const newDate = endOfDay(new Date(currentDate));
+ // Use startOfDay so the date passed to handleDateChange is a clean
+ // midnight — identical to what the Calendar picker sends.
+ const newDate = startOfDay(new Date(currentDate));
newDate.setDate(newDate.getDate() + days);
// Prevent jumping to future dates
- if (isAfter(startOfDay(newDate), startOfDay(today))) {
+ if (isAfter(newDate, today)) {
await onDateChange(today);
return;
}
diff --git a/apps/screenpipe-app-tauri/lib/actions/has-frames-date.ts b/apps/screenpipe-app-tauri/lib/actions/has-frames-date.ts
index 905a40f68..76b18dd46 100644
--- a/apps/screenpipe-app-tauri/lib/actions/has-frames-date.ts
+++ b/apps/screenpipe-app-tauri/lib/actions/has-frames-date.ts
@@ -53,13 +53,17 @@ export async function hasFramesForDate(date: Date): Promise<boolean> {
}
/**
- * Find the nearest date with frames in a single SQL query.
+ * Find the nearest date (local calendar day) with frames in a single SQL query.
* Replaces the recursive hasFramesForDate loop (up to 7 HTTP calls → 1).
*
- * @param targetDate - The date to search from
+ * Returns a Date at midnight local time for the day that has frames.
+ * This matches what Calendar picker and startOfDay produce, avoiding
+ * timezone bugs where a UTC timestamp maps to the wrong local date.
+ *
+ * @param targetDate - The date to search from (local time)
* @param direction - "backward" searches older dates, "forward" searches newer
* @param maxDays - Maximum number of days to search (default 7)
- * @returns The nearest Date with frames, or null if none found
+ * @returns A Date at midnight local time for the nearest day with frames, or null
*/
export async function findNearestDateWithFrames(
targetDate: Date,
@@ -128,9 +132,18 @@ export async function findNearestDateWithFrames(
return null;
}
+ // Convert UTC timestamp to LOCAL midnight for that calendar day.
+ // The DB stores UTC, but startOfDay/endOfDay in the caller use local time.
+ // Without this, a UTC timestamp like "2026-02-20T03:00Z" becomes Feb 19
+ // in PST, causing fetchTimeRange to load the wrong day's frames.
const nearestTimestamp = new Date(result[0].timestamp);
- console.log("findNearestDateWithFrames:", targetDate.toISOString(), "→", nearestTimestamp.toISOString());
- return nearestTimestamp;
+ const localMidnight = new Date(
+ nearestTimestamp.getFullYear(),
+ nearestTimestamp.getMonth(),
+ nearestTimestamp.getDate(),
+ );
+ console.log("findNearestDateWithFrames:", targetDate.toISOString(), "→ DB:", result[0].timestamp, "→ local day:", localMidnight.toISOString());
+ return localMidnight;
} catch (e) {
console.error("Error finding nearest date with frames:", e);
return null;
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx
index 00779e0ef..3cb4caa07 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-timeline-store.tsx
@@ -148,15 +148,16 @@ export const useTimelineStore = create<TimelineState>((set, get) => ({
requestTimeoutTimer = null;
}
requestRetryCount = 0;
- // Clear frames + timestamps so:
- // 1) request timeout logic correctly sees "no frames" and retries
- // 2) pendingNavigation effect triggers on first batch from new date
- set(() => ({
- frames: [],
+ // Keep existing frames visible to avoid the full-screen "Loading Timeline"
+ // blocker. The pendingNavigation effect in timeline.tsx filters by target
+ // date to find the right frame once new data arrives.
+ // Clear frameTimestamps so incoming frames from the new date aren't
+ // rejected as duplicates if they somehow share timestamps with old frames.
+ set((state) => ({
frameTimestamps: new Set<string>(),
sentRequests: new Set<string>(),
isLoading: true,
- loadingProgress: { loaded: 0, isStreaming: false },
+ loadingProgress: { loaded: state.frames.length, isStreaming: false },
error: null,
message: "loading...",
}));