Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/frontend/apps/impress/src/hook/useDate.tsx
Copy link
Collaborator

@AntoLC AntoLC Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const formatDefault: DateTimeFormatOptions = {
};

export const useDate = () => {
const { i18n } = useTranslation();
const { i18n, t } = useTranslation();

const formatDate = (
date: string,
Expand All @@ -22,7 +22,19 @@ export const useDate = () => {
};

const relativeDate = (date: string): string => {
return DateTime.fromISO(date).setLocale(i18n.language).toRelative() || '';
const dateToCompare = DateTime.fromISO(date);

if (!dateToCompare.isValid) {
return '';
}

const dateNow = DateTime.now();

const differenceInSeconds = dateNow.diff(dateToCompare).as('seconds');

return Math.abs(differenceInSeconds) >= 5
? dateToCompare.toRelative({ base: dateNow, locale: i18n.language })
: t('just now');
};

const calculateDaysLeft = (date: string, daysLimit: number): number =>
Expand Down
Loading