| 34 | } |
| 35 | |
| 36 | export function formatRelativeTimeShort(timestamp: number) { |
| 37 | const now = Date.now(); |
| 38 | const absSeconds = Math.abs(Math.round((timestamp - now) / 1000)); |
| 39 | if (absSeconds < 60) { |
| 40 | return "now"; |
| 41 | } |
| 42 | if (absSeconds < 60 * 60) { |
| 43 | return `${Math.max(1, Math.round(absSeconds / 60))}m`; |
| 44 | } |
| 45 | if (absSeconds < 60 * 60 * 24) { |
| 46 | return `${Math.max(1, Math.round(absSeconds / (60 * 60)))}h`; |
| 47 | } |
| 48 | if (absSeconds < 60 * 60 * 24 * 7) { |
| 49 | return `${Math.max(1, Math.round(absSeconds / (60 * 60 * 24)))}d`; |
| 50 | } |
| 51 | if (absSeconds < 60 * 60 * 24 * 30) { |
| 52 | return `${Math.max(1, Math.round(absSeconds / (60 * 60 * 24 * 7)))}w`; |
| 53 | } |
| 54 | if (absSeconds < 60 * 60 * 24 * 365) { |
| 55 | return `${Math.max(1, Math.round(absSeconds / (60 * 60 * 24 * 30)))}mo`; |
| 56 | } |
| 57 | return `${Math.max(1, Math.round(absSeconds / (60 * 60 * 24 * 365)))}y`; |
| 58 | } |