hibiscus/public/date.js

34 lines
969 B
JavaScript
Raw Normal View History

2024-03-28 10:42:52 +03:00
// Format time in "Jan 02, 2006" format
2024-03-27 11:51:33 +03:00
function formatDate(date) {
2024-05-05 13:06:20 +03:00
let dateFormat = new Intl.DateTimeFormat([langName, "en"], {
2024-03-27 11:51:33 +03:00
year: 'numeric',
month: 'short',
day: 'numeric'
})
2024-05-05 13:06:20 +03:00
return dateFormat.format(date)
2024-03-27 11:51:33 +03:00
}
2024-05-06 14:53:18 +03:00
async function graceActive() {
const response = await fetch("/api/grace");
const active = await response.text();
return active === "true"
}
2024-03-18 15:01:09 +03:00
2024-05-06 14:53:18 +03:00
// Set today's date and grace status
function updateTime() {
document.getElementById("today-date").innerText = formatDate(Date.now());
graceActive().then(v => document.getElementById("grace").hidden = !v)
2024-03-18 15:01:09 +03:00
}
2024-05-06 14:53:18 +03:00
// Start interval to update time at start of every minute
function callEveryMinute() {
setInterval(updateTime, 1000 * 60);
2024-03-18 15:01:09 +03:00
}
// Begin above interval
2024-05-06 14:53:18 +03:00
function beginTimeUpdater() {
const difference = (60 - new Date().getSeconds()) * 1000;
setTimeout(callEveryMinute, difference);
setTimeout(updateTime, difference);
updateTime();
2024-03-18 15:01:09 +03:00
}