From 8a1bd75d74c139561890b55a805d48a44301e4d9 Mon Sep 17 00:00:00 2001 From: cialloo Date: Sat, 4 Oct 2025 17:52:06 +0800 Subject: [PATCH] Enhance formatTimeAgo function to handle UTC timestamps and future timestamps --- src/App.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index f55d4c9..6ece149 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -133,9 +133,13 @@ function App() { return hours.toLocaleString() } - // Format time ago from timestamp + // Format time ago from timestamp (API returns UTC timestamps) const formatTimeAgo = (timestamp: number) => { - const seconds = Math.floor((Date.now() - timestamp) / 1000) + const now = Date.now() // Current local time + const utcNow = now - (new Date().getTimezoneOffset() * 60000) // Convert to UTC + const seconds = Math.floor((utcNow - timestamp) / 1000) + + if (seconds < 0) return 'just now' // Future timestamp if (seconds < 60) return `${seconds}s ago` const minutes = Math.floor(seconds / 60) if (minutes < 60) return `${minutes}m ago`