diff --git a/lib/browser.js b/lib/browser.js index 355b5af..2421b1c 100755 --- a/lib/browser.js +++ b/lib/browser.js @@ -60,7 +60,7 @@ hawk.client = { // Application time - var timestamp = options.timestamp || Math.floor((hawk.utils.now() + (options.localtimeOffsetMsec || 0)) / 1000) + var timestamp = options.timestamp || hawk.utils.now(options.localtimeOffsetMsec); // Validate credentials @@ -229,7 +229,7 @@ hawk.client = { // Application time - var timestamp = options.timestamp || Math.floor((hawk.utils.now() + (options.localtimeOffsetMsec || 0)) / 1000) + var timestamp = options.timestamp || hawk.utils.now(options.localtimeOffsetMsec); // Validate credentials @@ -359,8 +359,8 @@ hawk.utils = { setStorage: function (storage) { - var ntpOffset = hawk.utils.getNtpOffset() || 0; hawk.utils.storage = storage; + var ntpOffset = hawk.utils.getNtpOffset() || 0; hawk.utils.setNtpOffset(ntpOffset); }, @@ -380,9 +380,9 @@ hawk.utils = { return parseInt(hawk.utils.storage.getItem('hawk_ntp_offset') || '0', 10); }, - now: function () { + now: function (localtimeOffsetMsec) { - return (new Date()).getTime() + hawk.utils.getNtpOffset(); + return Math.floor(((new Date()).getTime() + (localtimeOffsetMsec || 0)) / 1000) + hawk.utils.getNtpOffset(); }, escapeHeaderAttribute: function (attribute) {