-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add local time to chat messages * See #1309
- Loading branch information
Showing
6 changed files
with
3,998 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.