diff options
author | href <href@random.sh> | 2021-09-03 04:02:43 +0200 |
---|---|---|
committer | href <href@random.sh> | 2021-09-03 04:02:43 +0200 |
commit | 5fc45a0e3b144b5e87845d068940afb90c3646a6 (patch) | |
tree | 364e9276a63bd23d8033cdae4a9e3e4d5fd755c1 /assets/controllers/time_controller.js | |
parent | improve puppets, fix uploads (diff) |
assets..
Diffstat (limited to '')
-rw-r--r-- | assets/controllers/time_controller.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/assets/controllers/time_controller.js b/assets/controllers/time_controller.js new file mode 100644 index 0000000..f09bd1a --- /dev/null +++ b/assets/controllers/time_controller.js @@ -0,0 +1,19 @@ +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); + } + +} + |