mirror of
https://github.com/Kizuren/statusPage.git
synced 2026-01-06 22:49:55 +01:00
Helper functions findClosestPoint & formatDate
This commit is contained in:
parent
958d645a98
commit
49c52ba2e2
1 changed files with 20 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue