Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdsdi3g/0b70936dbb9093c32818960963f51cd3 to your computer and use it in GitHub Desktop.
Save hdsdi3g/0b70936dbb9093c32818960963f51cd3 to your computer and use it in GitHub Desktop.
Computing client side time drift
$(document).ready(function() {
try {
$("#btnSession").addClass("active");
var server_time = ${System.currentTimeMillis()};
var client_time = Date.now();
var drift = (client_time - server_time) / 1000;
if (window.performance) {
if (window.performance.timing) {
if (window.performance.timing.responseStart) {
drift = (window.performance.timing.responseStart - server_time) / 1000;
}
}
}
if (Math.abs(drift) > 10) {
$("#display_drift_date").html(
i18n("userprofile.drifttime.value", drift) + "<br />" +
i18n("userprofile.drifttime.server", new Date(server_time)) + "<br />" +
i18n("userprofile.drifttime.warn")
);
$("#display_drift_date").addClass("alert");
if (Math.abs(drift) > 30) {
$("#display_drift_date").addClass("alert-error");
}
}
} catch(err) {
console.log(err);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment