Skip to content

Commit

Permalink
(fix) display durations longer than 24hrs (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
TP Honey committed May 6, 2022
1 parent 222be2f commit b1b4fa7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/shared/elapsed/elapsed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ const padTime = (n, withLetters) => n.toString().padStart(withLetters ? 1 : 2, '

const getTimeElapsed = ({ started, finished, withLetters = false }) => {
if (!started || !finished) return '';
const { hours, minutes, seconds } = intervalToDuration({
const {
days, hours, minutes, seconds,
} = intervalToDuration({
start: new Date(started * 1000),
end: new Date(finished * 1000),
});
if (withLetters) {
return `${hours ? `${padTime(hours, withLetters)}h` : ''} ${padTime(minutes, withLetters)}m ${padTime(seconds, withLetters)}s`;
return `${days ? `${padTime(days, withLetters)}d` : ''} ${hours ? `${padTime(hours, withLetters)}h` : ''} ${padTime(minutes, withLetters)}m ${padTime(seconds, withLetters)}s`;
}
return `${hours ? `${padTime(hours)}:` : ''}${padTime(minutes)}:${padTime(seconds)}`;
return `${days ? `${padTime(days)}` : ''} ${hours ? `${padTime(hours)}:` : ''}${padTime(minutes)}:${padTime(seconds)}`;
};

const getTimeElapsedSince = ({ dateSince }) => formatDistanceToNow(
Expand Down

0 comments on commit b1b4fa7

Please sign in to comment.