// This program has been developed by students from the bachelor Computer Science at Utrecht
// University within the Software Project course.
// © Copyright Utrecht University (Department of Information and Computing Sciences)
/**
 * Format a time duration like `HH:MM:SS.mmm`.
 *
 * @param durationMs time duration in milliseconds.
 * @return formatted time string.
 */
export default function formatDuration(durationMs: number): string {
  const isNegative = durationMs < 0;
  if (isNegative) durationMs = -durationMs;

  const hours = Math.floor(durationMs / 3600000);
  const minutes = Math.floor((durationMs % 3600000) / 60000);
  const seconds = Math.floor((durationMs % 60000) / 1000);
  const milliseconds = Math.floor(durationMs % 1000);

  return (isNegative ? '-' : '') +
    `${hours.toString().padStart(2, '0')}:` +
    `${minutes.toString().padStart(2, '0')}:` +
    `${seconds.toString().padStart(2, '0')}.` +
    `${milliseconds.toString().padStart(3, '0')}`;
}
