make dates rendered server-side & consistently in YYYY-MM-DD format

client-side time zone adjustment still persists---the server renders them out in UTC, but the client will adjust the date to its timezone during loading. 
this shouldn't cause any layout shifting because we use `font-variant-numeric: tabular-nums` (though Recursive seems to use tabular numbers either way.)
This commit is contained in:
りき萌 2025-01-13 22:36:34 +01:00
parent 81373b1076
commit 1953b649cf
3 changed files with 20 additions and 5 deletions

View file

@ -18,6 +18,10 @@ function branchIsOpen(branchID) {
return branchState[branchID];
}
function dateToString(date) {
return new Date(date - date.getTimezoneOffset() * 60000).toISOString().substring(0, 10);
}
export class Branch {
static branchesByNamedID = new Map();
static onAdded = [];
@ -70,11 +74,10 @@ export class Branch {
}
if (ulid.isCanonicalUlid(this.namedID)) {
// Adjust dates to fit the user's time zone.
let timestamp = ulid.getTimestamp(this.namedID);
let date = document.createElement("span");
date.classList.add("branch-date");
date.innerText = timestamp.toLocaleDateString();
this.buttonBar.insertBefore(date, this.buttonBar.firstChild);
let branchDate = this.buttonBar.getElementsByTagName("th-bd")[0];
branchDate.textContent = dateToString(timestamp);
}
for (let callback of Branch.onAdded) {