Render dates in correct timezone
This commit is contained in:
@@ -529,4 +529,8 @@ footer {
|
|||||||
.post-img-full {
|
.post-img-full {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,4 +77,24 @@ function togglePostFile(el) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
insertHeaderReplies()
|
||||||
|
}
|
||||||
|
|
||||||
|
initializePosts();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/dominicf2001/comfychan/internal/util"
|
"github.com/dominicf2001/comfychan/internal/util"
|
||||||
"github.com/dominicf2001/comfychan/web/views/shared"
|
"github.com/dominicf2001/comfychan/web/views/shared"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
templ PostAdminDialog(post database.Post) {
|
templ PostAdminDialog(post database.Post) {
|
||||||
@@ -105,8 +106,7 @@ templ PostOriginal(post database.Post, thread database.Thread) {
|
|||||||
{ thread.Subject }
|
{ thread.Subject }
|
||||||
</h1>
|
</h1>
|
||||||
<span class="post-author">{ post.Author }</span>
|
<span class="post-author">{ post.Author }</span>
|
||||||
<span class="post-date">{ post.CreatedAt.Format("01/02/2006") }</span>
|
<span class="post-datetime" data-utc={ post.CreatedAt.UTC().Format(time.RFC3339) }></span>
|
||||||
<span class="post-time">{ post.CreatedAt.Format("15:04") }</span>
|
|
||||||
<span
|
<span
|
||||||
_={ fmt.Sprintf(`
|
_={ fmt.Sprintf(`
|
||||||
on click set #newPostBody.value to #newPostBody.value + '>>%d\n'
|
on click set #newPostBody.value to #newPostBody.value + '>>%d\n'
|
||||||
@@ -138,8 +138,7 @@ templ PostReply(post database.Post, threadContext ThreadContext) {
|
|||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
<span class="post-author">{ post.Author }</span>
|
<span class="post-author">{ post.Author }</span>
|
||||||
<span class="post-date">{ post.CreatedAt.Format("01/02/2006") }</span>
|
<span class="post-datetime" data-utc={ post.CreatedAt.UTC().Format(time.RFC3339) }></span>
|
||||||
<span class="post-time">{ post.CreatedAt.Format("15:04") }</span>
|
|
||||||
<span
|
<span
|
||||||
_={ fmt.Sprintf(`
|
_={ fmt.Sprintf(`
|
||||||
on click set #newPostBody.value to #newPostBody.value + '>>%d\n'
|
on click set #newPostBody.value to #newPostBody.value + '>>%d\n'
|
||||||
@@ -232,7 +231,7 @@ templ Thread(board database.Board, thread database.Thread, posts []database.Post
|
|||||||
class="thread"
|
class="thread"
|
||||||
hx-get={ fmt.Sprintf("/hx/%s/threads/%d/posts", thread.BoardSlug, thread.Id) }
|
hx-get={ fmt.Sprintf("/hx/%s/threads/%d/posts", thread.BoardSlug, thread.Id) }
|
||||||
hx-trigger="refreshPosts from:body"
|
hx-trigger="refreshPosts from:body"
|
||||||
_="on htmx:afterSwap call insertHeaderReplies() then smoothScrollTo('bottom')"
|
_="on htmx:afterSwap call initializePosts() then smoothScrollTo('bottom')"
|
||||||
>
|
>
|
||||||
@Posts(posts, thread, threadContext)
|
@Posts(posts, thread, threadContext)
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user