1export const renderRelativeDate = (timestamp: number) => {
2 const elapsed = timestamp - new Date().getTime();
3 const units: Record<string, number> = {
4 year: 24 * 60 * 60 * 1000 * 365,
5 month: (24 * 60 * 60 * 1000 * 365) / 12,
6 day: 24 * 60 * 60 * 1000,
7 hour: 60 * 60 * 1000,
8 minute: 60 * 1000,
9 second: 1000
10 };
11 const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
12 for (const unit in units)
13 if (Math.abs(elapsed) > units[unit] || unit == 'second')
14 return rtf.format(Math.round(elapsed / units[unit]), unit as Intl.RelativeTimeFormatUnit);
15 return '';
16};
17export const renderDate = (timestamp: number) => {
18 return new Date(timestamp).toLocaleString('en-GB', {
19 year: '2-digit',
20 month: '2-digit',
21 day: '2-digit',
22 hour: '2-digit',
23 minute: '2-digit'
24 });
25};