x
1
<span></span>
1
<span><%= cookies[:timezone] %></span>
CSS is not required or multiple files are needed, check the notes.
1
2
3
4
5
6
7
8
9
10
11
import { Controller } from "@hotwired/stimulus"export default class extends Controller { connect() { document.cookie = `timezone=${encodeURIComponent(this.#timezone)}; path=/` } get #timezone() { return Intl.DateTimeFormat().resolvedOptions().timeZone }}
Initialization
You can use the cookie to set your timezone in rails.
<body data-controller="timezone-cookie">...</body>
class ApplicationController < ActionController::Base around_action :set_time_zone def set_time_zone Time.use_zone(cookies[:timezone]) { yield } endend