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
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 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 =>
Expand Down
Loading