chore: i18n time utils and use TFunction type (#6507) (#6539)

## Summary

Addresses two review comments from #6507:

- **`timeUtils.ts`** — route relative time strings (`just now`, `Xm
ago`, `Xh ago`, `Xd ago`) through i18n by accepting a `TFunction`
parameter and using new `time.relative.*` keys in `en-GB`
- **`ChatPanel.tsx`** — replace `ReturnType<typeof useTranslation>["t"]`
with `TFunction` from `i18next`

## Test plan
- [x] `task frontend:check` passes (695 tests)
This commit is contained in:
EthanHealy01
2026-06-05 09:45:27 +00:00
committed by GitHub
parent c93776e297
commit a61fe012d7
3 changed files with 16 additions and 7 deletions
+7 -5
View File
@@ -1,10 +1,12 @@
export function formatRelativeTime(timestamp: number): string {
import { TFunction } from "i18next";
export function formatRelativeTime(timestamp: number, t: TFunction): string {
const diff = Date.now() - timestamp;
const mins = Math.floor(diff / 60_000);
if (mins < 1) return "just now";
if (mins < 60) return `${mins}m ago`;
if (mins < 1) return t("time.relative.justNow");
if (mins < 60) return t("time.relative.minutesAgo", { count: mins });
const hours = Math.floor(mins / 60);
if (hours < 24) return `${hours}h ago`;
if (hours < 24) return t("time.relative.hoursAgo", { count: hours });
const days = Math.floor(hours / 24);
return `${days}d ago`;
return t("time.relative.daysAgo", { count: days });
}