============================================================================= Utility functions =============================================================================
function formatTime (time, format) {
  let showMs
  let showSc
  let showHr

  switch (format.toLowerCase()) {
    case 'hh:mm:ss.sss':
      showMs = true
      showSc = true
      showHr = true
      break
    case 'hh:mm:ss':
      showMs = !(!time.miliseconds)
      showSc = true
      showHr = true
      break
    case 'hh:mm':
      showMs = !(!time.miliseconds)
      showSc = showMs || !(!time.seconds)
      showHr = true
      break
    case 'mm:ss':
      showMs = !(!time.miliseconds)
      showSc = true
      showHr = !(!time.hours)
      break
    case 'mm:ss.sss':
      showMs = true
      showSc = true
      showHr = !(!time.hours)
      break
    default:
      throw new Error(TIME_FORMAT_ERRMSG)
  }

  let hh = zeroFill(2, time.hours)
  let mm = zeroFill(2, time.minutes)
  let ss = zeroFill(2, time.seconds)
  let sss = zeroFill(3, time.miliseconds)

  return (time.negative ? '-' : '') + (showHr ? (
    showMs ? `${hh}:${mm}:${ss}.${sss}` : showSc ? `${hh}:${mm}:${ss}` : `${hh}:${mm}`
  ) : (
    showMs ? `${mm}:${ss}.${sss}` : `${mm}:${ss}`
  ))
}