From 928c1a1d4e762ef86dab4df3a90494c61d6affe6 Mon Sep 17 00:00:00 2001 From: PaulVua Date: Tue, 17 Mar 2026 19:29:40 +0100 Subject: [PATCH] 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) --- html/admin.html | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/html/admin.html b/html/admin.html index 37d72f5..043ec44 100755 --- a/html/admin.html +++ b/html/admin.html @@ -588,29 +588,30 @@ window.onload = function() { document.getElementById("sys_UTC_time").value = response.system_utc_time; document.getElementById("RTC_utc_time").value = response.rtc_module_time; - // Get the time difference - const timeDiff = response.time_difference_seconds; - - // Reference to the alert container + // Compare RTC time with browser time (more reliable than system time) const alertContainer = document.getElementById("alert_container"); - - // Remove any previous alert alertContainer.innerHTML = ""; - // Add an alert based on time difference - if (typeof timeDiff === "number") { - if (timeDiff >= 0 && timeDiff <= 10) { + if (response.rtc_module_time) { + const rtcDate = new Date(response.rtc_module_time + ' UTC'); + const browserDate = new Date(); + const timeDiff = Math.abs(Math.round((browserDate - rtcDate) / 1000)); + + if (timeDiff <= 30) { alertContainer.innerHTML = ` `; - } else if (timeDiff > 10) { + } else { + const minutes = Math.floor(timeDiff / 60); + const label = minutes > 0 ? `${minutes} min ${timeDiff % 60} sec` : `${timeDiff} sec`; alertContainer.innerHTML = ` `; } - } + } }, error: function(xhr, status, error) { console.error('AJAX request failed:', status, error);