1 | import { bnToBn } from '../bn/toBn.js';
|
2 |
|
3 | function formatValue(elapsed) {
|
4 | if (elapsed < 15) {
|
5 | return `${elapsed.toFixed(1)}s`;
|
6 | }
|
7 | else if (elapsed < 60) {
|
8 | return `${elapsed | 0}s`;
|
9 | }
|
10 | else if (elapsed < 3600) {
|
11 | return `${elapsed / 60 | 0}m`;
|
12 | }
|
13 | return `${elapsed / 3600 | 0}h`;
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export function formatElapsed(now, value) {
|
20 | const tsNow = now?.getTime() || 0;
|
21 | const tsValue = value instanceof Date
|
22 | ? value.getTime()
|
23 | : bnToBn(value).toNumber();
|
24 | return (tsNow && tsValue)
|
25 | ? formatValue(Math.max(Math.abs(tsNow - tsValue), 0) / 1000)
|
26 | : '0.0s';
|
27 | }
|