Skip to content

fizray/clockzero

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClockZero

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.

Project Structure

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.md

Install

Run from root:

pnpm install

Dev

Run Vite dev server:

pnpm dev

Or run Vercel CLI dev server to test functions locally:

pnpm dev:vercel

Build & Typecheck

pnpm typecheck
pnpm build

Endpoints

  • GET /api/health - Basic service health
  • GET /api/time - Current server system time
  • GET /api/sync - Server system time with calibration metadata

Vercel Deployment

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

Time Synchronization Formula

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;

Accuracy Disclaimer

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

About

Minimalist time synchronization and device clock offset calibration tool using RTT tracking.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors