Import source: vault/lib/expiry-format

Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
arsam
2026-09-18 23:18:43 +03:30
parent 978ee06886
commit 355e22b669
+13
View File
@@ -0,0 +1,13 @@
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`;
}