Commits

Boris Nagaev committed 2b43924

Gather: gather small time difference in msec

Comments (0)

Files changed (2)

  */
 
 #include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
 #include <boost/algorithm/string/case_conv.hpp>
 
 #include <Wt/WApplication>
         return 10;
     } else if (type == TIMEZONE_OFFSET) {
         return 5;
+    } else if (type == TIME_ERROR) {
+        return 5;
     } else if (type == JAVA) {
         return 5;
     } else {
         return "locale";
     } else if (type == TIMEZONE_OFFSET) {
         return "timezone";
+    } else if (type == TIME_ERROR) {
+        return "timeerror";
     } else if (type == JAVA) {
         return "java";
     } else {
                                     "screen.height + ',' + screen.colorDepth"));
     doJavaScript(signal_.createCall(TO_S(TIMEZONE_OFFSET),
                                     "''+(new Date()).getTimezoneOffset()"));
+    doJavaScript(signal_.createCall(TO_S(TIME_ERROR),
+                                    "''+Date.now() % (60 * 60 * 1000)"));
     doJavaScript(signal_.createCall(TO_S(JAVA), "navigator.javaEnabled()"));
 }
 
         return;
     }
     if (significance(type) && !value.empty()) {
-        if (value.size() > MAX_SIZE) {
-            std::string w(value);
+        std::string w(value);
+        if (w.size() > MAX_SIZE) {
             w.resize(MAX_SIZE);
-            explorer_(type, w);
-        } else {
-            explorer_(type, value);
         }
+        if (type == TIME_ERROR) {
+            try {
+                int client_ms = boost::lexical_cast<int>(w);
+                int server_ms = now().toPosixTime()
+                                .time_of_day().total_milliseconds();
+                int d = (client_ms - server_ms) % (60 * 60 * 1000);
+                if (d > 30 * 60 * 1000) {
+                    // 30 mins
+                    d -= 60 * 60 * 1000;
+                }
+                if (d < -30 * 60 * 1000) {
+                    d += 60 * 60 * 1000;
+                }
+                // from -30min to +30min
+                w = TO_S(d);
+            } catch (...) {
+                return;
+            }
+        }
+        explorer_(type, w);
     }
 }
 
         SCREEN = 70, /**< Screen resolution, depth (weak virtuals evidence) */
         LOCALE = 80, /**< Browser locale (weak virtuals evidence) */
         TIMEZONE_OFFSET = 85, /**< Timezone offset (weak virtuals evidence) */
+        TIME_ERROR = 86, /**< Client - server diff in milliseconds (weak) */
         JAVA = 90 /**< Java enabled (weak virtuals evidence) */
     };
 
     */
     void explore_cookie();
 
-    /** Call explorer with PLUGINS, MIME_TYPES, SCREEN, TIMEZONE_OFFSET, JAVA.
+    /** Call PLUGINS, MIME_TYPES, SCREEN, TIMEZONE_OFFSET, TIME_ERROR JAVA.
     The method is called from the constructor through bound_post().
 
     The result is got through JavaScript call,