Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | export const timeAgo = (seconds: number): string => { const units: { [key: string]: number } = { year: 365 * 24 * 60 * 60, month: 30 * 24 * 60 * 60, week: 7 * 24 * 60 * 60, day: 24 * 60 * 60, hour: 60 * 60, minute: 60, second: 1, }; for (const unit in units) { const unitSeconds = units[unit]; Iif (seconds >= unitSeconds) { const value = Math.floor(seconds / unitSeconds); return `${value} ${unit}${value > 1 ? "s" : ""} ago`; } } return "just now"; }; |