import { type Duration } from 'date-fns';

export function msToDuration(ms: number): Duration {
  const seconds = Math.floor((ms / 1000) % 60);
  const minutes = Math.floor((ms / (1000 * 60)) % 60);
  const hours = Math.floor((ms / (1000 * 60 * 60)) % 24);
  const days = Math.floor(ms / (1000 * 60 * 60 * 24));

  return { days, hours, minutes, seconds };
}

export function secondsToDuration(secondsInput: number): Duration {
  const seconds = Math.floor(secondsInput % 60);
  const minutes = Math.floor((secondsInput / 60) % 60);
  const hours = Math.floor((secondsInput / 3600) % 24);
  const days = Math.floor(secondsInput / 86400);

  return { days, hours, minutes, seconds };
}
