diff --git a/src/screens/ModulesPage.tsx b/src/screens/ModulesPage.tsx index 9aa1551..bfa6972 100644 --- a/src/screens/ModulesPage.tsx +++ b/src/screens/ModulesPage.tsx @@ -588,6 +588,28 @@ function formatDate(dateStr?: string | null): string { } } +const DAY_MS = 86_400_000; + +/** "3 days ago", "5 mo ago", "2 y ago" from a repository's last push. */ +function timeAgo(dateStr: string | null | undefined, locale: string): string { + if (!dateStr) return "—"; + const t = Date.parse(dateStr); + if (Number.isNaN(t)) return "—"; + const days = Math.max(0, Math.floor((Date.now() - t) / DAY_MS)); + const ru = locale === "ru"; + if (days < 1) return ru ? "сегодня" : "today"; + if (days < 31) return ru ? `${days} дн. назад` : `${days} d ago`; + if (days < 365) return ru ? `${Math.floor(days / 30)} мес. назад` : `${Math.floor(days / 30)} mo ago`; + const years = Math.floor(days / 365); + return ru ? `${years} ${years === 1 ? "год" : years < 5 ? "года" : "лет"} назад` : `${years} y ago`; +} + +/** No commit for two years: probably written for a much older core. */ +function isStale(dateStr: string | null | undefined): boolean { + const t = dateStr ? Date.parse(dateStr) : NaN; + return !Number.isNaN(t) && Date.now() - t > 2 * 365 * DAY_MS; +} + export function ModulesPage({ serverId, onChanged, @@ -2011,7 +2033,7 @@ export function ModulesPage({ }; const cat = (publicCatalog?.categories ?? []).find((c) => c.code === curatedCategory(item.id)); return ( -
+
{cat ? (locale === "ru" ? cat.ru : cat.en) : ""} +
{isInstalled ? ( {cat ? (locale === "ru" ? cat.ru : cat.en) : ""} + + {timeAgo(item.pushed_at, locale)} + {item.stars}