Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use simple approach for LocalTimeHook #1318

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions assets/js/hooks/local-time-hooks.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
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])
let dt = new Date(this.el.textContent)
let options = {
timeStyle: "short",
dateStyle: "short",
}

this.el.textContent = formatted
this.el.classList.remove("opacity-0")
this.el.textContent = `${dt.toLocaleString("en-US", options)}`
this.el.classList.remove("invisible")
},
}

Expand Down
Loading
Loading