/**
 * Tiny display helpers shared across views. Kept in their own module so
 * adding a new consumer doesn't drag a React/DOM import along.
 */

/**
 * Format an ISO timestamp as a Chinese relative-time string ("3分钟前").
 * Accepts both "...Z" and naive "YYYY-MM-DD HH:MM:SS" (treated as UTC).
 */
export function formatRelativeTime(dateStr: string): string {
  const date = new Date(dateStr + (dateStr.endsWith('Z') ? '' : 'Z'))
  const now = new Date()
  const diffMs = now.getTime() - date.getTime()
  const diffMin = Math.floor(diffMs / 60000)
  if (diffMin < 1) return '刚刚'
  if (diffMin < 60) return `${diffMin}分钟前`
  const diffHr = Math.floor(diffMin / 60)
  if (diffHr < 24) return `${diffHr}小时前`
  const diffDay = Math.floor(diffHr / 24)
  return `${diffDay}天前`
}
