From 356c96c8e5d0710fe1d147121b851ff66e0f8687 Mon Sep 17 00:00:00 2001 From: buildwithricky Date: Fri, 31 Oct 2025 21:26:48 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20fix=20doc=20timestamp?= =?UTF-8?q?=20display?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented the logic to show 'Just now' instead of '0 seconds ago' when the difference is under one second. Signed-off-by: buildwithricky --- src/frontend/apps/impress/src/hook/useDate.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/frontend/apps/impress/src/hook/useDate.tsx b/src/frontend/apps/impress/src/hook/useDate.tsx index 14b09dbd82..7fea5befd7 100644 --- a/src/frontend/apps/impress/src/hook/useDate.tsx +++ b/src/frontend/apps/impress/src/hook/useDate.tsx @@ -10,7 +10,7 @@ const formatDefault: DateTimeFormatOptions = { }; export const useDate = () => { - const { i18n } = useTranslation(); + const { i18n ,t } = useTranslation(); const formatDate = ( date: string, @@ -22,7 +22,19 @@ export const useDate = () => { }; const relativeDate = (date: string): string => { - return DateTime.fromISO(date).setLocale(i18n.language).toRelative() || ''; + const dateTime = DateTime.fromISO(date).setLocale(i18n.language); + const relative = dateTime.toRelative(); + if (relative) { + const diffInSeconds = Math.abs(dateTime.diffNow('seconds').seconds); + if (diffInSeconds < 1) { + return t('just now'); + } + if (relative.includes('0 seconds') || relative.includes('0 second') || + relative.match(/0\s*(second|seconde|segundo|秒)/i)) { + return t('just now'); + } + } + return relative; }; const calculateDaysLeft = (date: string, daysLimit: number): number =>