add proper window open/close dates
This commit is contained in:
parent
f6c315d985
commit
c761a9ef26
4 changed files with 65 additions and 3 deletions
40
static/scripts/dates.js
Normal file
40
static/scripts/dates.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Converts server dates to local time.
|
||||
function changeDates() {
|
||||
const dateEls = document.querySelectorAll(".date");
|
||||
const today = new Date();
|
||||
const tomorrow = new Date(
|
||||
today.getFullYear(),
|
||||
today.getMonth(),
|
||||
today.getDate() + 1,
|
||||
);
|
||||
dateEls.forEach((el) => {
|
||||
const date = new Date(Number(el.dataset.ts)); // This is UTC
|
||||
const inner = el.querySelector(".inner");
|
||||
// Fallback: Normal date string representation
|
||||
let string = date.toString();
|
||||
const intl = new Intl.DateTimeFormat(undefined, {
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
const intlTimeOnly = new Intl.DateTimeFormat(undefined, {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
if (date.getDate() - today.getDate() == 0) {
|
||||
// If today
|
||||
string = `Today, ${intlTimeOnly.format(date)}`;
|
||||
} else if (date.getDate() - tomorrow.getDate() == 0) {
|
||||
// If tomorrow
|
||||
string = `Tomorrow, ${intlTimeOnly.format(date)}`;
|
||||
} else {
|
||||
// Use a proper formatted string
|
||||
string = intl.format(date);
|
||||
}
|
||||
|
||||
inner.innerHTML = string;
|
||||
});
|
||||
}
|
||||
|
||||
changeDates();
|
Loading…
Add table
Add a link
Reference in a new issue