feat(catalog): add catalog post previews

This commit is contained in:
Tom (plebeius.eth)
2024-06-08 11:27:29 +02:00
parent 0b2f02cd91
commit 88dcfcaca8
9 changed files with 249 additions and 44 deletions
+35
View File
@@ -33,3 +33,38 @@ export const getFormattedDate = (commentTimestamp: number) => {
}
return string;
};
export const getFormattedTimeAgo = (unixTimestamp: number): string => {
const currentTime = Date.now() / 1000;
const timeDifference = currentTime - unixTimestamp;
const t = i18next.t;
if (timeDifference < 120) {
return t('time_1_minute_ago');
}
if (timeDifference < 3600) {
return t('time_x_minutes_ago', { count: Math.floor(timeDifference / 60) });
}
if (timeDifference < 7200) {
return t('time_1_hour_ago');
}
if (timeDifference < 86400) {
return t('time_x_hours_ago', { count: Math.floor(timeDifference / 3600) });
}
if (timeDifference < 172800) {
return t('time_1_day_ago');
}
if (timeDifference < 2592000) {
return t('time_x_days_ago', { count: Math.floor(timeDifference / 86400) });
}
if (timeDifference < 5184000) {
return t('time_1_month_ago');
}
if (timeDifference < 31104000) {
return t('time_x_months_ago', { count: Math.floor(timeDifference / 2592000) });
}
if (timeDifference < 62208000) {
return t('time_1_year_ago');
}
return t('time_x_years_ago', { count: Math.floor(timeDifference / 31104000) });
};