diff --git a/index.js b/index.js index 0f1d5051..a08a2e82 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,8 @@ const Promise = require('bluebird'); const _ = require('lodash'); const util = require('./lib/util'); +// Tolerance for expiration measured in milliseconds +const TOLERANCE = 10 * 1000; /* eslint-disable global-require */ /** @exports smartcar */ @@ -31,7 +33,7 @@ smartcar.expired = function(access) { throw new TypeError('"access.expiration" argument must be a valid ISO date string'); } - return Date.now() > expiration; + return Date.now() > expiration - TOLERANCE; }; /** diff --git a/test/index.js b/test/index.js index 1211bf16..3ffa35f7 100644 --- a/test/index.js +++ b/test/index.js @@ -31,6 +31,9 @@ test('expired - string', function(t) { expiration = new Date(Date.now() - (60 * 1000)).toISOString(); t.true(smartcar.expired(expiration)); + expiration = new Date(Date.now()).toISOString(); + t.true(smartcar.expired(expiration)); + expiration = new Date(Date.now() + (60 * 1000)).toISOString(); t.false(smartcar.expired(expiration));