Clean clock calibration and device time offset checker.
In production, this application is deployed as a single project on Vercel containing both static files and Vercel Serverless Functions.
clockzero/
├─ api/ # Vercel Serverless Functions (/api/sync, /api/time, /api/health)
├─ public/ # Static assets
├─ src/ # Frontend React source code
│ └─ lib/
│ └─ shared.ts # Shared types and utilities
├─ index.html
├─ package.json
├─ tsconfig.json
├─ vite.config.ts
└─ README.mdRun from root:
pnpm installRun Vite dev server:
pnpm devOr run Vercel CLI dev server to test functions locally:
pnpm dev:vercelpnpm typecheck
pnpm buildGET /api/health- Basic service healthGET /api/time- Current server system timeGET /api/sync- Server system time with calibration metadata
Deploy this repository directly to Vercel with default settings:
- Root Directory:
./(default) - Framework Preset:
Vite - Build Command:
pnpm build - Output Directory:
dist - Install Command:
pnpm install
The client records and calculates offsets using Round-Trip Time (RTT):
const t0 = performance.now();
const local0 = Date.now();
const res = await fetch("/api/sync", { cache: "no-store" });
const data = await res.json();
const t3 = performance.now();
const rtt = t3 - t0;
const estimatedServerAtReceive = data.serverUnixMs + rtt / 2;
const estimatedLocalAtReceive = local0 + (t3 - t0);
const offsetMs = estimatedServerAtReceive - estimatedLocalAtReceive;
const estimatedAccuracyMs = rtt / 2;Browser clock accuracy depends on:
- Network RTT and jitter
- CPU scheduling and rendering frame rates (requestAnimationFrame/setInterval limits)
- Host OS clock synchronization on the server side