/
gr.ev.vl
/
TestGen
Обзор
Документация
Войти
/
gr.ev.vl
/
TestGen
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
backend/frontend/src/utils/format.ts
93 строки
3 KB
gr.ev.vl
Initial commit
06 июн 2026, 02:41
06 июн 2026, 02:41
02fb1fb
Код
Авторство
О чём код?
/** * Утилиты форматирования. */ export function formatDate(dateString: string): string { const date = new Date(dateString); return new Intl.DateTimeFormat("ru-RU", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit", }).format(date); } export function formatRelativeDate(dateString: string): string { const date = new Date(dateString); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffMinutes = Math.floor(diffMs / 60000); if (diffMinutes < 1) return "только что"; if (diffMinutes < 60) return `${diffMinutes} мин. назад`; const diffHours = Math.floor(diffMinutes / 60); if (diffHours < 24) return `${diffHours} ч. назад`; const diffDays = Math.floor(diffHours / 24); if (diffDays < 7) return `${diffDays} дн. назад`; return formatDate(dateString); } export function formatDuration(ms: number): string { const seconds = Math.floor(ms / 1000); if (seconds < 60) return `${seconds} с`; const minutes = Math.floor(seconds / 60); const remainingSeconds = seconds % 60; return `${minutes} мин ${remainingSeconds} с`; } export function truncateText(text: string, maxLength: number): string { if (text.length <= maxLength) return text; return text.slice(0, maxLength).trim() + "..."; } export const STATUS_LABELS: Record<string, string> = { draft: "Черновик", active: "Активный", archived: "Архивный", generated: "Сгенерирован", accepted: "Принят", rejected: "Отклонён", edited: "Отредактирован", assembled: "Собран", verified: "Верифицирован", approved: "Утверждён", rework: "На доработке", exported: "Экспортирован", pending: "Ожидает", running: "Выполняется", completed: "Завершён", failed: "Ошибка", cancelled: "Отменён", }; export const STATUS_COLORS: Record<string, string> = { draft: "gray", active: "green", archived: "orange", generated: "blue", accepted: "green", rejected: "red", edited: "yellow", assembled: "blue", verified: "green", approved: "emerald", rework: "orange", exported: "purple", pending: "gray", running: "blue", completed: "green", failed: "red", cancelled: "orange", }; export function getStatusLabel(status: string): string { return STATUS_LABELS[status] || status; } export function getStatusColor(status: string): string { return STATUS_COLORS[status] || "gray"; }