Use local time helper for comment dates

Also has the advantage you can hover to see the time.
This commit is contained in:
Kevin McConnell
2025-01-30 17:10:58 +00:00
parent 2e7870c6ff
commit b320b72bc6
2 changed files with 7 additions and 4 deletions
@@ -1,11 +1,12 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["time", "date", "datetime", "ago"]
static targets = ["time", "date", "datetime", "shortdate", "ago"]
initialize() {
this.timeFormatter = new Intl.DateTimeFormat(undefined, { timeStyle: "short" })
this.dateFormatter = new Intl.DateTimeFormat(undefined, { dateStyle: "long" })
this.shortDateFormatter = new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric" })
this.dateTimeFormatter = new Intl.DateTimeFormat(undefined, { timeStyle: "short", dateStyle: "short" })
this.agoFormatter = new AgoFormatter()
}
@@ -22,6 +23,10 @@ export default class extends Controller {
this.#formatTime(this.dateTimeFormatter, target)
}
shortdateTargetConnected(target) {
this.#formatTime(this.shortDateFormatter, target)
}
agoTargetConnected(target) {
this.#formatTime(this.agoFormatter, target)
}
+1 -3
View File
@@ -3,9 +3,7 @@
<div class="comment__author flex align-center gap-half">
<strong><%= link_to comment.creator.name, user_path(comment.creator), class: "txt-ink btn btn--plain", data: { turbo_frame: "_top" } %></strong>
<%= link_to bucket_bubble_path(comment.bubble.bucket, comment.bubble, anchor: "comment_#{comment.id}"), class: "txt-undecorated" do %>
<%= tag.time comment.created_at, class: "comment__timestamp" do %>
<%= comment.created_at.strftime("%b %d") %>
<% end %>
<%= local_datetime_tag comment.created_at, style: :shortdate, class: "comment__timestamp" %>
<% end %>
<% if comment.creator == Current.user %>