All files / shared / utils format.ts

74.19% Statements 46/62
58.33% Branches 21/36
83.33% Functions 5/6
92% Lines 23/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  858x 858x 858x 858x 858x 858x 858x 858x     2338x 2338x 2338x       4730x 2838x 2838x 2838x 2786x 2714x 2714x 2000x 2000x 2000x 24x 24x    
export function formatDateTime(dateStr: string | null | undefined): string {
 I Iif (!dateStr) return '\u2014'
  const d = new Date(dateStr)
  const year = d.getFullYear()
  const month = String(d.getMonth() + 1).padStart(2, '0')
  const day = String(d.getDate()).padStart(2, '0')
  const hours = String(d.getHours()).padStart(2, '0')
  const minutes = String(d.getMinutes()).padStart(2, '0')
  return `${year}-${month}-${day} ${hours}:${minutes}`
}
 
eIxport function abbreviateNumber(n: number | undefined | null): string {
 I if (n == null) return '\u2014'
 E if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`
  if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`
  return String(n)
}
 
export function formatRelativeTime(dateStr: string | null | undefined): string {
  Iif (!dateStr) return 'Never'
  const diff = Date.now() - new Date(dateStr).getTime()
  const mins = Math.floor(diff / 60000)
  Iif (mins < 1) return 'now'
  if (mins < 60) return `${mins} min ago`
  const hours = Math.floor(mins / 60)
 I if (hours < 24) return `${hours}h ago`
  const days = Math.floor(hours / 24)
  Iif (days < 7) return `${days}d ago`
  return new Date(dateStr).toLocaleDateString()
}