diff --git a/resources/static/shared/modules/interaction_data.js b/resources/static/shared/modules/interaction_data.js index f9de4013f329732d62db7fe36bfe7c5423408999..e07e04de42e27fea588e31ad5ddd805040ba694b 100644 --- a/resources/static/shared/modules/interaction_data.js +++ b/resources/static/shared/modules/interaction_data.js @@ -23,6 +23,8 @@ // listen for events via the mediator? BrowserID.Modules.InteractionData = (function() { + "use strict"; + var bid = BrowserID, model = bid.Models.InteractionData, network = bid.Network, @@ -98,10 +100,16 @@ BrowserID.Modules.InteractionData = (function() { return; } + // server_time is sent in milliseconds. The promise to users and data + // safety is the timestamp would be at a 10 minute resolution. Round to the + // nearest 10 minute mark. + var TEN_MINS_IN_MS = 10 * 60 * 1000, + roundedServerTime = Math.round(result.server_time / TEN_MINS_IN_MS) * TEN_MINS_IN_MS; + var currentData = { event_stream: self.initialEventStream, sample_rate: sampleRate, - timestamp: result.server_time, + timestamp: roundedServerTime, local_timestamp: self.startTime.toString(), lang: dom.getAttr('html', 'lang') || null, }; diff --git a/resources/static/test/cases/shared/modules/interaction_data.js b/resources/static/test/cases/shared/modules/interaction_data.js index f2b6b675d0ae32888178c1e63639f8f270c3e7dd..35940a19c9bd04e043467b3a9ea3d1df6a5c8e2b 100644 --- a/resources/static/test/cases/shared/modules/interaction_data.js +++ b/resources/static/test/cases/shared/modules/interaction_data.js @@ -235,4 +235,15 @@ }); }); + asyncTest("timestamp rounded to 10 minute intervals", function() { + var TEN_MINS_IN_MS = 10 * 60 * 1000; + createController(); + network.withContext(function() { + var timestamp = controller.getCurrent().timestamp; + ok(timestamp, "a timestamp has been passed: " + timestamp); + equal(timestamp % TEN_MINS_IN_MS, 0, "timestamp has been rounded to a 10 minute interval"); + start(); + }); + }); + }());