From 49c52ba2e2fcc1cb5e9b7bf1b01c03bd88ca5336 Mon Sep 17 00:00:00 2001 From: ybouane Date: Wed, 9 Oct 2024 22:33:34 -0400 Subject: [PATCH] Helper functions findClosestPoint & formatDate --- static/client.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/static/client.js b/static/client.js index abc634a..d8d5be8 100644 --- a/static/client.js +++ b/static/client.js @@ -50,4 +50,23 @@ document.addEventListener("DOMContentLoaded", async () => { }; refreshStatus(); setInterval(refreshStatus, 60_000); // Refresh every minute -}); \ No newline at end of file +}); +const formatDate = (date) => new Intl.DateTimeFormat('en-US', { + month: 'long', + day: 'numeric', + year: 'numeric', + hour: 'numeric', + minute: '2-digit', + hour12: true +}).format(date); + +const findClosestPoint = (logs, t, maxDistance=Infinity) => { + let best; + for(let log of logs) { + let d = Math.abs(log.t-t); + if(d <= maxDistance && (!best || d