import { Controller } from "stimulus"; import { DateTime } from "luxon"; export default class extends Controller { static values = { format: String }; connect() { var browserTz = Intl.DateTimeFormat().resolvedOptions().timeZone; var browserLocale = Intl.DateTimeFormat().resolvedOptions().locale; var locale = document.body.dataset.locale || browserLocale || "en"; var tz = document.body.dataset.tz || browserTz || "UTC"; var style = DateTime[this.formatValue]; console.log(locale,tz,style); this.date = DateTime.fromISO(this.element.dateTime).setZone(tz).setLocale(locale); this.element.innerText = this.date.toLocaleString(style); } }