% stimulus_controller = 'fields--date' form ||= current_fields_form user_tz = defined?(current_user.time_zone) ? ActiveSupport::TimeZone.find_tzinfo(current_user.time_zone).name : nil current_team_time_zone = if current_user&.respond_to?(:current_team) && current_team.time_zone current_team.time_zone else "UTC" end team_tz = ActiveSupport::TimeZone.find_tzinfo(current_team_time_zone)&.name options ||= {} data_options ||= {} other_options ||= {} # data_options represents the iso8601 date and time value in a hidden input field. # The value we display on screen is in options[:value]. data_options[:id] ||= form.field_id(method) data_options[:class] = "hidden" data_options[:value] = form.object.send(method)&.in_time_zone(current_time_zone)&.iso8601 data_options = data_options.merge({ data: {"#{stimulus_controller}-target": 'field' }}) # localized display options options[:id] ||= "#{form.field_id(method)}_display" options[:class] = "form-control single-daterange w-full border-slate-300 dark:bg-slate-800 dark:border-slate-900 disabled:bg-slate-200 disabled:dark:bg-slate-700 #{options[:class]}".strip raw_value = form.object.send(method)&.in_time_zone(current_user&.time_zone || current_team_time_zone || "UTC") options[:value] = raw_value && I18n.l(raw_value, format: :date_and_time_field) options = options.merge({ data: {"#{stimulus_controller}-target": 'displayField' }}) %> <%# Although we pass options below to `text_field`, we need to pass options here %> <%# too because the id we set earlier is not the usual `form.field_id(method)`. %> <%= render 'shared/fields/field', form: form, method: method, options: options, other_options: other_options do %> <% content_for :field do %>