From b474771b890a5addca483260a674119563eb2227 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 28 Nov 2023 10:12:50 +0100 Subject: account for small time drifts --- html/index.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/html/index.html b/html/index.html index 7ac4100..a78efbc 100644 --- a/html/index.html +++ b/html/index.html @@ -106,11 +106,17 @@ const MSECS_IN_DAY = 24 * MSECS_IN_HOUR; function date_to_readable(date) { const now = Date.now(); - if (Date.now() < date) { - return 'future???'; + let duration = now - date; + + if (Math.abs(duration) < 2 * MSECS_IN_SEC) { + // Most likely, the time is not synchronized either on the server or + // the client. + return 'now'; } - let duration = now - date; + if (duration < 0) { + return 'future???'; + } let days = Math.floor(duration / MSECS_IN_DAY); duration -= days * MSECS_IN_DAY; -- cgit v1.2.3