// Utility helpers for time-related operations const MS_THRESHOLD = 1_000_000_000_000; /** * Strictly for persisted timestamps: * return epoch seconds as bigint (floor) */ export function nowSecBigInt(): bigint { return BigInt(Math.floor(Date.now() / 1000)); } /** * Convert a runtime value into epoch seconds (bigint). * Numbers > 1e12 are treated as milliseconds and converted down. */ export function toSecBigInt(value: number | bigint): bigint { if (typeof value === 'bigint') { return value; } if (!Number.isFinite(value)) { return BigInt(0); } if (Math.abs(value) > MS_THRESHOLD) { return BigInt(Math.floor(value / 1000)); } return BigInt(Math.floor(value)); } export function nowEpochMsBigInt(): bigint { return BigInt(Date.now()); } export function nowMs(): number { return Date.now(); }