heartwood every commit a ring
594 B raw
const timeDiff = (time) => {
  const timeNow = new Date();
  return timeNow - time;
};

const timeString = (timeDiff) => {
  // timeDiff should be milliseconds
  const timerTotal = [
    timeDiff / 1000 / 60 / 60, // Hours (uncapped so long sessions don't wrap)
    (timeDiff / 1000 / 60) % 60, // Minutes
    (timeDiff / 1000) % 60, // Seconds
  ];
  return timerTotal
    .map((timer) => {
      let stringTime = Math.floor(timer).toString();
      if (stringTime.length < 2) stringTime = `0${stringTime}`;
      return stringTime;
    })
    .join(":");
};

export { timeDiff, timeString };