Render dates in correct timezone

This commit is contained in:
Dominic Ferrando
2025-04-28 14:13:53 -04:00
parent 564a7f3ff9
commit 49f4f452a6
3 changed files with 29 additions and 6 deletions
+4
View File
@@ -529,4 +529,8 @@ footer {
.post-img-full {
max-width: 100%;
}
textarea {
font-size: 16px;
}
}
+21 -1
View File
@@ -77,4 +77,24 @@ function togglePostFile(el) {
}
}
insertHeaderReplies()
function initializePosts() {
// set dates to correct timezone
document.querySelectorAll('.post-datetime').forEach(el => {
const utcDateStr = el.getAttribute('data-utc');
const localDate = new Date(utcDateStr);
const hours = localDate.getHours() % 12 || 12;
const minutes = String(localDate.getMinutes()).padStart(2, '0');
const ampm = localDate.getHours() >= 12 ? 'PM' : 'AM';
const month = String(localDate.getMonth() + 1).padStart(2, '0');
const day = String(localDate.getDate()).padStart(2, '0');
const year = localDate.getFullYear();
el.textContent = `${month}/${day}/${year} ${hours}:${minutes} ${ampm}`;
});
insertHeaderReplies()
}
initializePosts();