export function formatTimestamp(value: string | null | undefined): string {
  if (!value) {
    return '—';
  }

  const date = new Date(value);
  if (Number.isNaN(date.getTime())) {
    return value;
  }

  return new Intl.DateTimeFormat('ru-RU', {
    day: '2-digit',
    month: '2-digit',
    year: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
  }).format(date);
}

export function formatUnixMs(value: number | null | undefined): string {
  if (value == null) {
    return '—';
  }
  return formatTimestamp(new Date(value).toISOString());
}

export function formatClockTime(valueMs: number | null | undefined): string {
  if (valueMs == null || !Number.isFinite(valueMs)) {
    return '—';
  }
  return new Intl.DateTimeFormat('ru-RU', {
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
  }).format(new Date(valueMs));
}
