From 35fa26fb5355f9e598a1c6159a44948f19f73990 Mon Sep 17 00:00:00 2001
From: Shane Tomlinson <stomlinson@mozilla.com>
Date: Mon, 18 Jun 2012 17:36:32 +0100
Subject: [PATCH] Round the timestamp to the neartest to minutes.

issue #1732
---
 resources/static/shared/modules/interaction_data.js   | 10 +++++++++-
 .../test/cases/shared/modules/interaction_data.js     | 11 +++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/resources/static/shared/modules/interaction_data.js b/resources/static/shared/modules/interaction_data.js
index f9de4013f..1114a3173 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 resultion.  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 f2b6b675d..35940a19c 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();
+    });
+  });
+
 }());
-- 
GitLab