Sha256: 1659b8fd756f75c4caf17742338e034dc9a14b5b71a8d9e5cd94053b9f3825c6
Contents?: true
Size: 902 Bytes
Versions: 35
Compression:
Stored size: 902 Bytes
Contents
import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = [ "time", "date", "datetime" ] initialize() { this.timeFormatter = new Intl.DateTimeFormat(undefined, { timeStyle: "short" }) this.dateFormatter = new Intl.DateTimeFormat(undefined, { dateStyle: "long" }) this.dateTimeFormatter = new Intl.DateTimeFormat(undefined, { timeStyle: "short", dateStyle: "short" }) } timeTargetConnected(target) { this.#formatTime(this.timeFormatter, target) } dateTargetConnected(target) { this.#formatTime(this.dateFormatter, target) } datetimeTargetConnected(target) { this.#formatTime(this.dateTimeFormatter, target) } #formatTime(formatter, target) { const dt = new Date(target.getAttribute("datetime")) target.textContent = formatter.format(dt) target.title = this.dateTimeFormatter.format(dt) } }
Version data entries
35 entries across 35 versions & 1 rubygems