diff --git a/lib/fiatrateservice.js b/lib/fiatrateservice.js index 018e69f..0db7e85 100644 --- a/lib/fiatrateservice.js +++ b/lib/fiatrateservice.js @@ -119,7 +119,7 @@ FiatRateService.prototype.getRate = function(opts, cb) { async.map([].concat(ts), function(ts, cb) { self.storage.fetchFiatRate(provider, opts.code, ts, function(err, rate) { if (err) return cb(err); - if (rate && (now - rate.ts) > Defaults.FIAT_RATE_MAX_LOOK_BACK_TIME * 60 * 1000) rate = null; + if (rate && (ts - rate.ts) > Defaults.FIAT_RATE_MAX_LOOK_BACK_TIME * 60 * 1000) rate = null; return cb(null, { ts: +ts, diff --git a/test/integration/fiatrateservice.js b/test/integration/fiatrateservice.js index 3efbc46..7a60e0b 100644 --- a/test/integration/fiatrateservice.js +++ b/test/integration/fiatrateservice.js @@ -182,16 +182,16 @@ describe('Fiat rate service', function() { value: 123.45, }], function(err) { should.not.exist(err); - clock.tick((120 * 60 - 1) * 1000); // Almost 2 hours + clock.tick(24 * 3600 * 1000); // Some time in the future service.getRate({ + ts: 2 * 3600 * 1000 - 1, // almost 2 hours code: 'USD', }, function(err, res) { should.not.exist(err); res.rate.should.equal(123.45); res.fetchedOn.should.equal(0); - clock.restore(); - clock.tick(2 * 1000); // 2 seconds later... service.getRate({ + ts: 2 * 3600 * 1000 + 1, // just past 2 hours code: 'USD', }, function(err, res) { should.not.exist(err);