Files
CVault/vault/lib/expiry-format.ts
arsam 355e22b669 Import source: vault/lib/expiry-format
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
2026-09-18 23:18:43 +03:30

14 lines
613 B
TypeScript

export function formatExpiry(expiresAt: string | null | undefined): string | null {
if (!expiresAt) return null;
const ms = new Date(expiresAt).getTime() - Date.now();
if (ms <= 0) return "Expired";
const totalMins = Math.floor(ms / 60000);
if (totalMins < 60) return `Expires in ${totalMins}m`;
const hrs = Math.floor(totalMins / 60);
const mins = totalMins % 60;
if (hrs < 24) return mins > 0 ? `Expires in ${hrs}h ${mins}m` : `Expires in ${hrs}h`;
const days = Math.floor(hrs / 24);
const remHrs = hrs % 24;
return remHrs > 0 ? `Expires in ${days}d ${remHrs}h` : `Expires in ${days}d`;
}