diff --git a/js/date-fmt.js b/js/date-fmt.js new file mode 100644 index 0000000..521f206 --- /dev/null +++ b/js/date-fmt.js @@ -0,0 +1,10 @@ +document.addEventListener("DOMContentLoaded", () => { + const timestampSpans = document.getElementsByClassName("timestamp"); + for (let timestampSpan of timestampSpans) { + const timestamp = parseInt(timestampSpan.dataset.utc); + if (!isNaN(timestamp)) { + const date = new Date(timestamp * 1000); + timestampSpan.textContent = date.toLocaleString(); + } + } +}) diff --git a/views/base.etlua b/views/base.etlua index a50f454..5da0af2 100644 --- a/views/base.etlua +++ b/views/base.etlua @@ -17,5 +17,6 @@ + diff --git a/views/common/timestamp.etlua b/views/common/timestamp.etlua new file mode 100644 index 0000000..1649021 --- /dev/null +++ b/views/common/timestamp.etlua @@ -0,0 +1 @@ +<%= os.date("%c", timestamp) %> \ No newline at end of file diff --git a/views/threads/post.etlua b/views/threads/post.etlua index 4288fc9..1f39934 100644 --- a/views/threads/post.etlua +++ b/views/threads/post.etlua @@ -22,9 +22,9 @@ %> <% if tonumber(post.edited_at) > tonumber(post.created_at) then -%> - Edited at <%= os.date("%c", post.edited_at) %> + Edited at <% render("views.common.timestamp", {timestamp = post.edited_at}) -%> <% else -%> - Posted on <%= os.date("%c", post.created_at) %> + Posted on <% render("views.common.timestamp", {timestamp = post.created_at}) -%> <% end -%> @@ -47,8 +47,8 @@ end if show_reply then local d = post.created_at < post.edited_at and post.edited_at or post.created_at - local quote_src_text = ("On [url=%s]%s[/url], [url=%s]%s[/url] said:"):format( - post_url, os.date("%c", d), url_for("user", {username = post.username}), post.username + local quote_src_text = ("[url=%s]%s said:[/url]"):format( + post_url, post.username ) local reply_text = ("%s\n[quote]%s[/quote]\n---\n\n"):format(quote_src_text, post.original_markup) %> diff --git a/views/topics/topic.etlua b/views/topics/topic.etlua index f6fde8b..d4cc1a7 100644 --- a/views/topics/topic.etlua +++ b/views/topics/topic.etlua @@ -48,11 +48,11 @@ "><%= thread.title %> • Started by ><%= thread.started_by %> - on <%= os.date("%c", thread.created_at) %> + on <% render("views.common.timestamp", {timestamp = thread.created_at}) -%> Latest post by "><%= thread.latest_post_username %> - ">on <%= os.date("%c", thread.latest_post_created_at) %>: + ">on <% render("views.common.timestamp", {timestamp = thread.latest_post_created_at}) -%>: <%- thread.latest_post_content %> diff --git a/views/topics/topics.etlua b/views/topics/topics.etlua index 950e3ed..95d3d35 100644 --- a/views/topics/topics.etlua +++ b/views/topics/topics.etlua @@ -21,7 +21,7 @@ <%= topic.description %> <% if topic.latest_thread_username then %> - Latest thread: "><%= topic.latest_thread_title %> by "><%= topic.latest_thread_username %> on <%= os.date("%c", topic.latest_thread_created_at) %> + Latest thread: "><%= topic.latest_thread_title %> by "><%= topic.latest_thread_username %> on <% render("views.common.timestamp", {timestamp = topic.latest_thread_created_at}) -%> <% else %> No threads yet. diff --git a/views/user/user.etlua b/views/user/user.etlua index f0dc350..c73ee36 100644 --- a/views/user/user.etlua +++ b/views/user/user.etlua @@ -27,9 +27,9 @@
" title="Permalink"> <% if tonumber(post.edited_at) > tonumber(post.created_at) then -%> - Edited in <%= post.thread_title %> at <%= os.date("%c", post.edited_at) %> + Edited in <%= post.thread_title %> at <% render("views.common.timestamp", {timestamp = post.edited_at}) -%> <% else -%> - Posted in <%= post.thread_title %> on <%= os.date("%c", post.created_at) %> + Posted in <%= post.thread_title %> on <% render("views.common.timestamp", {timestamp = post.created_at}) -%> <% end -%>
@@ -48,12 +48,12 @@

Moderator controls

<% if user:is_guest() then %> -

This user is a guest. They signed up on <%= os.date("%c", user.created_at) %>.

+

This user is a guest. They signed up on <% render("views.common.timestamp", {timestamp = user.created_at}) -%>.

">
<% else %> <% --[[ user is not guest ]] %> -

This user signed up on <%= os.date("%c", user.created_at) %> and was confirmed on <%= os.date("%c", user.confirmed_on) %>.

+

This user signed up on <% render("views.common.timestamp", {timestamp = user.created_at}) -%> and was confirmed on <% render("views.common.timestamp", {timestamp = user.confirmed_on}) %>.

<% if user.permission < me.permission then %>
">