From 44be5ba36de9782321a52cfa8ec989d8bb9761b4 Mon Sep 17 00:00:00 2001 From: Pouria Delfanazari Date: Mon, 11 Mar 2024 17:58:42 -0700 Subject: [PATCH] Show 'now' for post time if it's less than 1s --- src/lib/utils/time.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/time.ts b/src/lib/utils/time.ts index e9b51c0a..5c8ed975 100644 --- a/src/lib/utils/time.ts +++ b/src/lib/utils/time.ts @@ -11,8 +11,9 @@ export function getRelativeTime(dates: string) { const date = new Date(dates); const seconds = Math.floor((Date.now() - date.getTime()) / 1000); const interval = intervals.find((i) => i.seconds < seconds); - if (!interval) return; + if (!interval) return "now"; const count = Math.floor(seconds / interval.seconds); + if (count < 1) return "now"; return `${count}${interval.label}`; }