Use timezone preference

This commit is contained in:
Midgard 2022-06-09 15:27:50 +02:00
parent bf5798c4e5
commit c62f9c0ddc
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 9 additions and 1 deletions

View file

@ -85,6 +85,11 @@ function padLeft(input, width, padding=" ") {
return text;
}
function toTimeZone(date, timezoneString) {
// https://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript
return new Date(date.toLocaleString("en-US", {timeZone: timezoneString}));
}
function formatDdddMmYy(date) {
return `${date.getFullYear()}-${padLeft(date.getMonth() + 1, 2, "0")}-${padLeft(date.getDate(), 2, "0")}`;
}

View file

@ -16,7 +16,10 @@ async function createMessageElement(client, post, lastTime, lastAuthor) {
messageDiv.className = "message";
messageDiv.innerText = transformMessageText(post.message);
const createAt = new Date(post.create_at);
let createAt = new Date(post.create_at);
if (client.me.timezone.useAutomaticTimezone !== "true") {
createAt = toTimeZone(createAt, client.me.timezone.manualTimezone);
}
const createAtDiv = document.createElement("time");
createAtDiv.className = "create_at";
const sim = dateSimilarity(lastTime, createAt);