import 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, 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); }