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)
}