Newer
Older
tgclient-mcp / frontend / src / format.js
// Panel formatters. Формат времени локаль-чувствителен (t() читает locale ref
// из i18n — вызовы в computed/шаблонах перерисовываются сами).
import { t } from './i18n/index.js'

export function fmtAgo(iso) {
  if (!iso) return t('time.never')
  const seconds = Math.floor((Date.now() - new Date(iso).getTime()) / 1000)
  if (seconds < 5) return t('time.now')
  if (seconds < 60) return t('time.secondsAgo', { n: seconds })
  if (seconds < 3600) return t('time.minutesAgo', { n: Math.floor(seconds / 60) })
  if (seconds < 86400) return t('time.hoursAgo', { n: Math.floor(seconds / 3600) })
  return t('time.daysAgo', { n: Math.floor(seconds / 86400) })
}

// Маска телефона +7***123 — как держит бэкенд (коды/номера не светим в списках)
export function maskPhone(phone) {
  if (!phone) return t('time.never')
  if (phone.length < 8) return phone
  return phone.slice(0, 3) + '***' + phone.slice(-3)
}

export function fmtDateTime(iso) {
  if (!iso) return '—'
  return new Date(iso).toLocaleString()
}