Something went wrong. Try again.
Effortlessly glide through your todos
Something went wrong. Try again.
123456789101112131415161718import type { LocalTask } from './task-store';
/** * Produces a strictly increasing per-row LWW timestamp even when the device * clock moves backwards or the server previously acknowledged a future value. */export function nextTaskUpdatedAt( task: Pick<LocalTask, 'updatedAt' | 'syncedAt'>, wallNow = Date.now(),): number { if (!Number.isSafeInteger(wallNow) || wallNow < 0) throw new Error('Invalid task clock'); const floor = Math.max(task.updatedAt, task.syncedAt ?? -1); if (!Number.isSafeInteger(floor) || floor < 0 || floor >= Number.MAX_SAFE_INTEGER) { throw new Error('Task timestamp cannot advance safely'); } return Math.max(wallNow, floor + 1);}