mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-23 10:48:01 +00:00
Initial rebrand: @polkadot -> @pezkuwi (14 packages)
- Package namespace: @polkadot/* -> @pezkuwi/* - Repository: polkadot-js/common -> pezkuwichain/pezkuwi-common - Author: Pezkuwi Team <team@pezkuwichain.io> Core packages: - @pezkuwi/util (utilities) - @pezkuwi/util-crypto (crypto primitives) - @pezkuwi/keyring (account management) - @pezkuwi/networks (chain metadata) - @pezkuwi/hw-ledger (Ledger hardware wallet) - @pezkuwi/x-* (10 polyfill packages) Total: 14 packages Upstream: polkadot-js/common v14.0.1
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// Copyright 2017-2025 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BN } from '../bn/bn.js';
|
||||
import type { ToBn } from '../types.js';
|
||||
|
||||
import { bnToBn } from '../bn/toBn.js';
|
||||
|
||||
/** @internal */
|
||||
function formatValue (elapsed: number): string {
|
||||
if (elapsed < 15) {
|
||||
return `${elapsed.toFixed(1)}s`;
|
||||
} else if (elapsed < 60) {
|
||||
return `${elapsed | 0}s`;
|
||||
} else if (elapsed < 3600) {
|
||||
return `${elapsed / 60 | 0}m`;
|
||||
}
|
||||
|
||||
return `${elapsed / 3600 | 0}h`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name formatElapsed
|
||||
* @description Formats an elapsed value into s, m, h or day segments
|
||||
*/
|
||||
export function formatElapsed <ExtToBn extends ToBn> (now?: Date | null, value?: bigint | BN | ExtToBn | Date | number | null): string {
|
||||
const tsNow = now?.getTime() || 0;
|
||||
const tsValue = value instanceof Date
|
||||
? value.getTime()
|
||||
: bnToBn(value).toNumber();
|
||||
|
||||
return (tsNow && tsValue)
|
||||
? formatValue(Math.max(Math.abs(tsNow - tsValue), 0) / 1000)
|
||||
: '0.0s';
|
||||
}
|
||||
Reference in New Issue
Block a user