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