administrate
administrate copied to clipboard
Global Date/Time Field Timezone
Is there any way to set a global date field display timezone other than changing the Rails config setting?
I'd rather not make an app-wide timezone change for displaying dates in an admin.
If not, I can create a PR. Any suggestions on where it should be set?
@nickcharlton - Any thoughts on this? It's currently resolving to the application time zone (https://github.com/thoughtbot/administrate/pull/1070).
I think there is a way: generate attribute partials for the Date and DateTime fields and use the Rails helpers to convert the dates into the desired timezone. It's not ideal since you need to duplicate it in up to 6 partials, but it's an option.
I'm wondering if the right solution here is to use the timezone of the user who's currently using the dashboard.
Are you providing this as an option? I think that's where I'd start and then from there having Administrate know how to pick that up would be ideal.
I think there is a way: generate attribute partials for the Date and DateTime fields and use the Rails helpers to convert the dates into the desired timezone. It's not ideal since you need to duplicate it in up to 6 partials, but it's an option.
I think this is the right approach. Personally I don't mind the form being in a different format as the user can pick a date and time here. So that would leave me with 4 partials. If you use a localization file for your date and time formats you could use one of those formats or create your own.
en.yml
en:
time:
formats:
...
long: "%B %d, %Y %H:%M"
...
e.g. app/views/fields/date_time/_index.html.erb
<% if field.data %>
<%= I18n.l(field.data, format: :long) %>
<% end %>