From 13b7d03987a317098ac9a0f1f877cd3f3940c3a2 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 21 Dec 2018 11:09:19 -0800 Subject: [PATCH] wallet: improved date handling --- lib/wallet/http.js | 10 ++++------ lib/wallet/rpc.js | 12 ++++-------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/wallet/http.js b/lib/wallet/http.js index cc1fee0cd1..ff4ab9588a 100644 --- a/lib/wallet/http.js +++ b/lib/wallet/http.js @@ -769,13 +769,12 @@ class HTTP extends Server { const reverse = valid.bool('reverse', false); const limit = valid.u32('limit', 100); const after = valid.brhash('after'); + const date = valid.str('date'); let time = valid.u32('time'); - let date = valid.str('date'); if (date && !time) { - date = new Date(date); - enforce(date.toString() !== 'Invalid Date', 'Invalid date.'); time = util.time(date); + enforce(time, 'Invalid date.'); } enforce(limit <= this.options.maxTxs, @@ -819,13 +818,12 @@ class HTTP extends Server { const reverse = valid.bool('reverse'); const limit = valid.u32('limit'); const after = valid.brhash('after'); + const date = valid.str('date'); let time = valid.u32('time'); - let date = valid.str('date'); if (date && !time) { - date = new Date(date); - enforce(date.toString() !== 'Invalid Date', 'Invalid date.'); time = util.time(date); + enforce(time, 'Invalid date.'); } enforce(limit <= this.options.maxTxs, diff --git a/lib/wallet/rpc.js b/lib/wallet/rpc.js index 0027f3c099..4c8f1d40de 100644 --- a/lib/wallet/rpc.js +++ b/lib/wallet/rpc.js @@ -1248,12 +1248,10 @@ class RPC extends RPCBase { throw new RPCError(errs.INVALID_PARAMETER, `Limit above max of ${this.maxTxs}.`); - const date = new Date(timestamp); - if (date.toString() === 'Invalid Date') + const time = util.time(timestamp); + if (!time) throw new RPCError(errs.INVALID_PARAMETER, 'Invalid timestamp.'); - const time = util.time(date); - const recs = await wallet.listHistoryByTime(name, {time, limit, reverse}); const out = []; @@ -1337,12 +1335,10 @@ class RPC extends RPCBase { if (limit > 100) throw new RPCError(errs.INVALID_PARAMETER, 'Limit above max of 100.'); - const date = new Date(timestamp); - if (date.toString() === 'Invalid Date') + const time = util.time(timestamp); + if (!time) throw new RPCError(errs.INVALID_PARAMETER, 'Invalid timestamp.'); - const time = util.time(date); - const recs = await wallet.listUnconfirmedByTime( name, {time, limit, reverse} );