hibiscus/public/date.js

36 lines
942 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-03-18 15:01:09 +03:00
// Set today's date
function updateDate() {
let timeField = document.getElementById("today-date")
2024-05-05 13:06:20 +03:00
if (graceActive) {
let graceField = document.getElementById("grace")
graceField.hidden = false
}
timeField.innerText = formatDate(Date.now())
2024-03-18 15:01:09 +03:00
}
2024-03-28 10:42:52 +03:00
// Start interval to update today's date every hour at 00:00
2024-03-18 15:01:09 +03:00
function callEveryHour() {
setInterval(updateDate, 1000 * 60 * 60);
}
// Begin above interval
function beginDateUpdater() {
let nextDate = new Date();
nextDate.setHours(nextDate.getHours() + 1);
nextDate.setMinutes(0);
nextDate.setSeconds(0);
const difference = nextDate - new Date();
setTimeout(callEveryHour, difference);
}