mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(catalog): add catalog post previews
This commit is contained in:
@@ -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) });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user