add date and time functions.
This commit is contained in:
parent
64813d3de1
commit
c95681ae3f
@ -506,7 +506,7 @@ Block.prototype.inspect = function inspect() {
|
|||||||
hash: utils.revHex(this.hash('hex')),
|
hash: utils.revHex(this.hash('hex')),
|
||||||
size: this.getSize(),
|
size: this.getSize(),
|
||||||
virtualSize: this.getVirtualSize(),
|
virtualSize: this.getVirtualSize(),
|
||||||
date: new Date(this.ts * 1000).toISOString(),
|
date: utils.date(this.ts),
|
||||||
version: this.version,
|
version: this.version,
|
||||||
prevBlock: utils.revHex(this.prevBlock),
|
prevBlock: utils.revHex(this.prevBlock),
|
||||||
merkleRoot: utils.revHex(this.merkleRoot),
|
merkleRoot: utils.revHex(this.merkleRoot),
|
||||||
|
|||||||
@ -95,7 +95,7 @@ Headers.prototype.inspect = function inspect() {
|
|||||||
delete copy._raw;
|
delete copy._raw;
|
||||||
copy.hash = this.hash('hex');
|
copy.hash = this.hash('hex');
|
||||||
copy.rhash = this.rhash;
|
copy.rhash = this.rhash;
|
||||||
copy.date = new Date((copy.ts || 0) * 1000).toISOString();
|
copy.date = utils.date(copy.ts);
|
||||||
return copy;
|
return copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -246,7 +246,7 @@ MerkleBlock.prototype.inspect = function inspect() {
|
|||||||
delete copy._chain;
|
delete copy._chain;
|
||||||
copy.hash = this.hash('hex');
|
copy.hash = this.hash('hex');
|
||||||
copy.rhash = this.rhash;
|
copy.rhash = this.rhash;
|
||||||
copy.date = new Date((copy.ts || 0) * 1000).toISOString();
|
copy.date = utils.date(copy.ts);
|
||||||
return copy;
|
return copy;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -851,7 +851,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer, callback) {
|
|||||||
'Status: tip=%s ts=%s height=%d blocks=%d orphans=%d active=%d'
|
'Status: tip=%s ts=%s height=%d blocks=%d orphans=%d active=%d'
|
||||||
+ ' queue=%d target=%s peers=%d pending=%d highest=%d jobs=%d',
|
+ ' queue=%d target=%s peers=%d pending=%d highest=%d jobs=%d',
|
||||||
block.rhash,
|
block.rhash,
|
||||||
new Date(block.ts * 1000).toISOString().slice(0, -5) + 'Z',
|
utils.date(block.ts),
|
||||||
self.chain.height,
|
self.chain.height,
|
||||||
self.chain.total,
|
self.chain.total,
|
||||||
self.chain.orphan.count,
|
self.chain.orphan.count,
|
||||||
@ -1477,7 +1477,7 @@ Pool.prototype.searchWallet = function(wallet, callback) {
|
|||||||
bcoin.debug(
|
bcoin.debug(
|
||||||
'Reverted chain to height=%d (%s)',
|
'Reverted chain to height=%d (%s)',
|
||||||
self.chain.height,
|
self.chain.height,
|
||||||
new Date(self.chain.tip.ts * 1000)
|
utils.date(self.chain.tip.ts)
|
||||||
);
|
);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
@ -1495,11 +1495,11 @@ Pool.prototype.searchWallet = function(wallet, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
bcoin.debug('Wallet time: %s', new Date(ts * 1000));
|
bcoin.debug('Wallet time: %s', utils.date(ts));
|
||||||
bcoin.debug(
|
bcoin.debug(
|
||||||
'Reverted chain to height=%d (%s)',
|
'Reverted chain to height=%d (%s)',
|
||||||
self.chain.height,
|
self.chain.height,
|
||||||
new Date(self.chain.tip.ts * 1000)
|
utils.date(self.chain.tip.ts)
|
||||||
);
|
);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
|||||||
@ -1564,7 +1564,7 @@ TX.prototype.inspect = function inspect() {
|
|||||||
minFee: utils.btc(this.getMinFee()),
|
minFee: utils.btc(this.getMinFee()),
|
||||||
confirmations: this.getConfirmations(),
|
confirmations: this.getConfirmations(),
|
||||||
priority: this.getPriority().toString(10),
|
priority: this.getPriority().toString(10),
|
||||||
date: new Date((this.ts || this.ps) * 1000).toISOString(),
|
date: utils.date(this.ts || this.ps),
|
||||||
block: this.block ? utils.revHex(this.block) : null,
|
block: this.block ? utils.revHex(this.block) : null,
|
||||||
ts: this.ts,
|
ts: this.ts,
|
||||||
ps: this.ps,
|
ps: this.ps,
|
||||||
|
|||||||
@ -1226,6 +1226,32 @@ utils.now = function now() {
|
|||||||
return +new Date() / 1000 | 0;
|
return +new Date() / 1000 | 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a Date ISO string from time in unix time (seconds).
|
||||||
|
* @param {Number?} - Seconds in unix time.
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
|
||||||
|
utils.date = function date(ts) {
|
||||||
|
if (ts == null)
|
||||||
|
ts = utils.now();
|
||||||
|
|
||||||
|
return new Date(ts * 1000).toISOString().slice(0, -5) + 'Z';
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get unix seconds from a Date string.
|
||||||
|
* @param {String} date - Date ISO String.
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
utils.time = function time(date) {
|
||||||
|
if (date == null)
|
||||||
|
return utils.now();
|
||||||
|
|
||||||
|
return new Date(date) / 1000 | 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UINT32_MAX
|
* UINT32_MAX
|
||||||
* @type BN
|
* @type BN
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user