/
man4j
/
consistique
Обзор
Документация
Войти
/
man4j
/
consistique
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/shared/lib/dates.ts
16 строк
637 B
Vladimir
fixes
25 июл 2026, 10:58
25 июл 2026, 10:58
5ffc474
Код
Авторство
О чём код?
export function formatTimestamp(value: string | null | undefined) { if (!value) return '—'; return new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short', }).format(new Date(value)); } export function formatAge(value: string | null | undefined) { if (!value) return '—'; const seconds = Math.max(0, Math.round((Date.now() - new Date(value).getTime()) / 1000)); if (seconds < 60) return `${seconds}s ago`; if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`; if (seconds < 86_400) return `${Math.floor(seconds / 3600)}h ago`; return `${Math.floor(seconds / 86_400)}d ago`; }