Admin: comparer RTC vs heure navigateur au lieu de system time

L'heure du navigateur (PC/Mac/tablette) est fiable meme sans internet
grace a la pile interne. Plus pertinent que system time Linux qui
n'est pas utilise par le capteur et peut etre faux sans NTP.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
PaulVua
2026-03-17 19:29:40 +01:00
parent 24cb96e9a9
commit 928c1a1d4e

View File

@@ -588,26 +588,27 @@ window.onload = function() {
document.getElementById("sys_UTC_time").value = response.system_utc_time; document.getElementById("sys_UTC_time").value = response.system_utc_time;
document.getElementById("RTC_utc_time").value = response.rtc_module_time; document.getElementById("RTC_utc_time").value = response.rtc_module_time;
// Get the time difference // Compare RTC time with browser time (more reliable than system time)
const timeDiff = response.time_difference_seconds;
// Reference to the alert container
const alertContainer = document.getElementById("alert_container"); const alertContainer = document.getElementById("alert_container");
// Remove any previous alert
alertContainer.innerHTML = ""; alertContainer.innerHTML = "";
// Add an alert based on time difference if (response.rtc_module_time) {
if (typeof timeDiff === "number") { const rtcDate = new Date(response.rtc_module_time + ' UTC');
if (timeDiff >= 0 && timeDiff <= 10) { const browserDate = new Date();
const timeDiff = Math.abs(Math.round((browserDate - rtcDate) / 1000));
if (timeDiff <= 30) {
alertContainer.innerHTML = ` alertContainer.innerHTML = `
<div class="alert alert-success" role="alert"> <div class="alert alert-success" role="alert">
RTC and system time are in sync (Difference: ${timeDiff} sec). RTC synchronise avec l'heure du navigateur (ecart: ${timeDiff} sec).
</div>`; </div>`;
} else if (timeDiff > 10) { } else {
const minutes = Math.floor(timeDiff / 60);
const label = minutes > 0 ? `${minutes} min ${timeDiff % 60} sec` : `${timeDiff} sec`;
alertContainer.innerHTML = ` alertContainer.innerHTML = `
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
RTC time is out of sync! (Difference: ${timeDiff} sec). RTC desynchronise ! Ecart avec le navigateur: ${label}.
Utilisez "Synchroniser le RTC" ci-dessous.
</div>`; </div>`;
} }
} }