| 7 | type Translate = (key: TimeKey, params?: Record<string, string | number>) => string |
| 8 | |
| 9 | export function getRelativeTime(dateString: string, t: Translate): string { |
| 10 | const date = new Date(dateString) |
| 11 | const now = new Date() |
| 12 | const diffMs = now.getTime() - date.getTime() |
| 13 | const diffSeconds = Math.floor(diffMs / 1000) |
| 14 | const diffMinutes = Math.floor(diffSeconds / 60) |
| 15 | const diffHours = Math.floor(diffMinutes / 60) |
| 16 | const diffDays = Math.floor(diffHours / 24) |
| 17 | |
| 18 | if (diffSeconds < 60) return t("common.time.justNow") |
| 19 | if (diffMinutes < 60) return t("common.time.minutesAgo.short", { count: diffMinutes }) |
| 20 | if (diffHours < 24) return t("common.time.hoursAgo.short", { count: diffHours }) |
| 21 | return t("common.time.daysAgo.short", { count: diffDays }) |
| 22 | } |