Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

fix(client): display SQLite UTC timestamps in the viewer's local time

Tashfeen62807538ac82
diff --git a/client/src/lib/utils.ts b/client/src/lib/utils.ts
index bd0c391d..6586a622 100644
--- a/client/src/lib/utils.ts
+++ b/client/src/lib/utils.ts
@@ -4,3 +4,26 @@ import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
+
+// SQLite stores timestamps as `YYYY-MM-DD HH:MM:SS` with no timezone marker, so
+// passing them straight to `new Date(...)` makes the browser read them as LOCAL
+// time when they are actually UTC — shifting every displayed time by the
+// viewer's offset. These helpers tag the value as UTC before parsing. (#170)
+
+/** Convert a SQLite UTC datetime string into an ISO-8601 UTC string. */
+export function sqliteUtcToIso(value: string): string {
+ // Already ISO (has 'T' and a zone/offset)? Leave it alone.
+ if (value.includes('T')) return value;
+ return value.replace(' ', 'T') + 'Z';
+}
+
+/** Format a SQLite UTC datetime string as the viewer's local time-of-day. */
+export function formatSqliteUtcToLocalTime(
+ value: string | null | undefined,
+ options: Intl.DateTimeFormatOptions = { hour: '2-digit', minute: '2-digit', second: '2-digit' },
+): string {
+ if (!value) return '—';
+ const date = new Date(sqliteUtcToIso(value));
+ if (isNaN(date.getTime())) return '—';
+ return date.toLocaleTimeString([], options);
+}
diff --git a/client/src/pages/AnalyticsPage.tsx b/client/src/pages/AnalyticsPage.tsx
index bb197cbc..e72dd800 100644
--- a/client/src/pages/AnalyticsPage.tsx
+++ b/client/src/pages/AnalyticsPage.tsx
@@ -8,6 +8,7 @@ import { apiFetch } from '@/lib/api'
import { Button } from '@/components/ui/button'
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
import { PageHeader } from '@/components/page-header'
+import { formatSqliteUtcToLocalTime } from '@/lib/utils'
type TimeRange = '24h' | '7d' | '30d'
@@ -232,7 +233,7 @@ export default function AnalyticsPage() {
<TableCell className="pl-4 text-xs">{e.platform}</TableCell>
<TableCell className="text-xs max-w-[200px] truncate">{e.error}</TableCell>
<TableCell className="text-right text-xs text-muted-foreground tabular-nums pr-4">
- {new Date(e.createdAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
+ {formatSqliteUtcToLocalTime(e.createdAt, { hour: '2-digit', minute: '2-digit' })}
</TableCell>
</TableRow>
))}