diff options
| author | Adam Soltys <[email protected]> | 2025-01-21 23:26:32 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-01-21 23:26:32 -0800 |
| commit | a70316e64bcc9bad7fb626056f9cc58d1858dff9 (patch) | |
| tree | a185e9ee5210d5a83be08cfa15cd6343e2188b3e /src/lib/utils.ts | |
| parent | dd86867462148daa88a3f3727434773d67dcab43 (diff) | |
| download | coinos-ui-a70316e64bcc9bad7fb626056f9cc58d1858dff9.tar.gz coinos-ui-a70316e64bcc9bad7fb626056f9cc58d1858dff9.zip | |
notes
Diffstat (limited to 'src/lib/utils.ts')
| -rw-r--r-- | src/lib/utils.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts index e2e19b05..2e1bb840 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -4,6 +4,12 @@ import { page } from "$app/stores"; import { PUBLIC_COINOS_NETWORK, PUBLIC_COINOS_URL } from "$env/static/public"; import { bytesToHex } from "@noble/hashes/utils"; import { toast } from "@zerodevx/svelte-toast"; +import { + differenceInDays, + differenceInHours, + differenceInMinutes, + differenceInSeconds, +} from "date-fns"; import { decrypt } from "nostr-tools/nip49"; import { get as getStore } from "svelte/store"; @@ -434,3 +440,19 @@ export const versions = { }[PUBLIC_COINOS_NETWORK]; export const str = (s) => s.toString(); + +export const ago = (t) => { + const now = new Date(); + const date = new Date(t * 1000); + const seconds = differenceInSeconds(now, date); + if (seconds < 60) return `${seconds}s`; + + const minutes = differenceInMinutes(now, date); + if (minutes < 60) return `${minutes}m`; + + const hours = differenceInHours(now, date); + if (hours < 24) return `${hours}h`; + + const days = differenceInDays(now, date); + return `${days}d`; +}; |
