diff options
author | Jaz <ericvolp12@gmail.com> | 2023-05-30 18:25:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-30 18:25:29 -0700 |
commit | 09ade363fdcfadb03433385e0c5510bc58438a65 (patch) | |
tree | 710af28d1eb7f70acf81f86acb44759439e164fc /src/lib/strings/time.ts | |
parent | 7f76c2d67e62ba2d10e8b17673a7bbcf7248564f (diff) | |
parent | e224569a11b82361d782324a63bdfc19d44a3201 (diff) | |
download | voidsky-09ade363fdcfadb03433385e0c5510bc58438a65.tar.zst |
Merge branch 'main' into inherit_system_theme
Diffstat (limited to 'src/lib/strings/time.ts')
-rw-r--r-- | src/lib/strings/time.ts | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/strings/time.ts b/src/lib/strings/time.ts index 588b84459..3f2847558 100644 --- a/src/lib/strings/time.ts +++ b/src/lib/strings/time.ts @@ -1,8 +1,8 @@ const MINUTE = 60 const HOUR = MINUTE * 60 const DAY = HOUR * 24 -const MONTH = DAY * 28 -const YEAR = DAY * 365 +const WEEK = DAY * 7 + export function ago(date: number | string | Date): string { let ts: number if (typeof date === 'string') { @@ -19,12 +19,14 @@ export function ago(date: number | string | Date): string { return `${Math.floor(diffSeconds / MINUTE)}m` } else if (diffSeconds < DAY) { return `${Math.floor(diffSeconds / HOUR)}h` - } else if (diffSeconds < MONTH) { + } else if (diffSeconds < WEEK) { return `${Math.floor(diffSeconds / DAY)}d` - } else if (diffSeconds < YEAR) { - return `${Math.floor(diffSeconds / MONTH)}mo` } else { - return new Date(ts).toLocaleDateString() + return new Date(ts).toLocaleDateString('en-us', { + year: 'numeric', + month: 'short', + day: 'numeric', + }) } } |