/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/app/src/utils/time.ts
22 строки
898 B
Adam
chore(app): i18n sync (#15362)
27 фев 2026, 18:45
Не верифицирован
27 фев 2026, 18:45
6ef3af7
Код
Авторство
О чём код?
type TimeKey = | "common.time.justNow" | "common.time.minutesAgo.short" | "common.time.hoursAgo.short" | "common.time.daysAgo.short" type Translate = (key: TimeKey, params?: Record<string, string | number>) => string export function getRelativeTime(dateString: string, t: Translate): string { const date = new Date(dateString) const now = new Date() const diffMs = now.getTime() - date.getTime() const diffSeconds = Math.floor(diffMs / 1000) const diffMinutes = Math.floor(diffSeconds / 60) const diffHours = Math.floor(diffMinutes / 60) const diffDays = Math.floor(diffHours / 24) if (diffSeconds < 60) return t("common.time.justNow") if (diffMinutes < 60) return t("common.time.minutesAgo.short", { count: diffMinutes }) if (diffHours < 24) return t("common.time.hoursAgo.short", { count: diffHours }) return t("common.time.daysAgo.short", { count: diffDays }) }