Skip to content

Commit

Permalink
multiple units displayed at once
Browse files Browse the repository at this point in the history
  • Loading branch information
apburnie committed Jun 22, 2022
1 parent 6efc570 commit 260f1a4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions explorer/client/src/utils/timeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,23 @@ export const timeAgo = (epochMilliSecs: number | null): string => {
['sec', 1000],
];

for (const [label, denom] of timeUnit) {
const amount = Math.floor(timeDiff / denom);

const convertAmount = (amount: number, label: string) => {
if (amount > 1) return `${amount} ${label}s`;
if (amount === 1) return `${amount} ${label}`;
return '';
};

let resultArr = [];
let timeCol = timeDiff;

for (const [label, denom] of timeUnit) {
let whole = Math.floor(timeCol / denom);
resultArr.push(convertAmount(whole, label));

timeCol = timeCol - whole * denom;
}

return `< 1 sec`;
const result = resultArr.join(' ').trim();

return result ? result : `< 1 sec`;
};

0 comments on commit 260f1a4

Please sign in to comment.