export default (time, fmt) => {
  let format = fmt || "hh:mm:ss";
  const dhms = /d+/.test(format) && {
    "d+": parseInt(time / 24 / 60 / 60, 10),
    "h+": parseInt((time / 60 / 60) % 24, 10),
    "m+": parseInt((time / 60) % 60, 10),
    "s+": parseInt(time % 60, 10)
  };
  const hms = /hh+/.test(format) && {
    "h+": parseInt(time / 60 / 60, 10),
    "m+": parseInt((time / 60) % 60, 10),
    "s+": parseInt(time % 60, 10)
  };
  const ms = /mm+/.test(format) && {
    "m+": parseInt(time / 60, 10),
    "s+": parseInt(time % 60, 10)
  };
  const o = dhms || hms || ms;

  for (const k in o) {
    if (new RegExp(`(${k})`).test(format)) {
      let str = o[k] + "";
      str = str.length > 1 ? str : 0 + str;
      format = format.replace(RegExp.$1, str);
    }
  }

  return format;
};
