Helper functions findClosestPoint & formatDate

This commit is contained in:
ybouane 2024-10-09 22:33:34 -04:00
parent 958d645a98
commit 49c52ba2e2

View file

@ -50,4 +50,23 @@ document.addEventListener("DOMContentLoaded", async () => {
};
refreshStatus();
setInterval(refreshStatus, 60_000); // Refresh every minute
});
});
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<Math.abs(best.t-t))) {
best = log;
}
}
return best;
}