All files / src/utils formatters.ts

100% Statements 18/18
100% Branches 9/9
100% Functions 3/3
100% Lines 18/18

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      1x 94x 94x 2x 2x         1x 35x 35x         1x 73x 71x 71x 71x 71x 71x 71x 71x 71x  
/**
 * Formats a given number of seconds into a human-readable interval (e.g., "5m", "1h")
 */
export function formatInterval(seconds: number): string {
  if (seconds < 60) return `${seconds}s`;
  if (seconds < 3600) return `${Math.floor(seconds / 60)}m`;
  return `${Math.floor(seconds / 3600)}h`;
}
 
/**
 * Formats a decimal/fraction into a clean percentage
 */
export function formatPercentage(value: number, decimals: number = 2): string {
  return `${Number(value.toFixed(decimals))}%`;
}
 
/**
 * Standardizes datetime display across the app (includes seconds)
 */
export function formatDateTime(isoString: string | null | undefined): string {
  if (!isoString) return "N/A";
  return new Date(isoString).toLocaleString(undefined, {
    month: "short",
    day: "numeric",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
  });
}