diff --git a/js/util.js b/js/util.js index 39e5c77..1697ba9 100644 --- a/js/util.js +++ b/js/util.js @@ -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")}`; } diff --git a/js/view/messages.js b/js/view/messages.js index 5827e6d..e52842d 100644 --- a/js/view/messages.js +++ b/js/view/messages.js @@ -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);