Skip to content

Commit

Permalink
Add local time to chat messages
Browse files Browse the repository at this point in the history
* Add local time to chat messages
* See #1309
  • Loading branch information
axelclark committed Apr 13, 2024
1 parent 23e5199 commit ff65dbd
Show file tree
Hide file tree
Showing 6 changed files with 3,998 additions and 1 deletion.
2 changes: 2 additions & 0 deletions assets/js/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import SortableInputsFor from "./sortable-hooks"
import ChatScrollToBottom from "./chat-hooks"
import LocalTimeHook from "./local-time-hooks"

export default {
SortableInputsFor,
ChatScrollToBottom,
LocalTimeHook,
}
29 changes: 29 additions & 0 deletions assets/js/hooks/local-time-hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DateTime } from "../../vendor/luxon"
const LocalTimeHook = {
mounted() {
this.updated()
},
updated() {
const format = this.el.dataset.format
const preset = this.el.dataset.preset
const locale = this.el.dataset.locale
const dtString = this.el.textContent.trim()
const dt = DateTime.fromISO(dtString).setLocale(locale)

let formatted
if (format) {
if (format === "relative") {
formatted = dt.toRelative()
} else {
formatted = dt.toFormat(format)
}
} else {
formatted = dt.toLocaleString(DateTime[preset])
}

this.el.textContent = formatted
this.el.classList.remove("opacity-0")
},
}

export default LocalTimeHook
Loading

0 comments on commit ff65dbd

Please sign in to comment.