From 57c7a60860bf84ab3115d4eb036fde483e1d07b1 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Sun, 20 Oct 2024 00:36:08 +0800 Subject: [PATCH] feat: formatRelativeTime add seconds --- lib/utils.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/utils.ts b/lib/utils.ts index 5dc9143..e22f1b1 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -90,17 +90,19 @@ export function formatRelativeTime(timestamp: number): string { const diff = now - timestamp; const hours = Math.floor(diff / (1000 * 60 * 60)); const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); + const seconds = Math.floor((diff % (1000 * 60)) / 1000); if (hours > 24) { const days = Math.floor(hours / 24); return `${days}d`; } else if (hours > 0) { return `${hours}h`; - } else if (minutes >= 0) { + } else if (minutes > 0) { return `${minutes}m`; - } else { - return "just now"; + } else if (seconds >= 0) { + return `${seconds}s`; } + return "0s"; } export function formatTime(timestamp: number): string {