trestle
trestle copied to clipboard
Show timestamps in browser local timezone
Timestamps are displayed in the Rails app's local time (most likely UTC) which isn't terribly helpful for admins trying to determine when an action took place, since the timezone of the timestamp isn't even displayed. Unfortunately this isn't one of those problems that's easily solved, despite how frequently it comes up.
The best solution that I'm aware of is to have a bit of js that grabs all <time> tags on the page and uses the datetime attribute of them to create a js date and then convert it to the browser's local time, and then update the contents of the tag with the appropriate localized display version of that time/date.
If you're open to this, I can give it a stab in a PR. Also open to other, more elegant suggestions.
I like this idea, and would definitely accept (and happy to work together / provide feedback on) a PR that achieves this. A few thoughts in no particular order:
-
The
trestle-authplugin has aconfig.auth.time_zoneoption allowing you to define how the time zone is set for each request on a per-user basis. Not saying this solves the problem but just letting you know it is there. See https://github.com/TrestleAdmin/trestle-auth/blob/master/lib/generators/trestle/auth/install/templates/basic.rb.erb#L59-L64 -
I do think this should be configurable. There is currently a
timestamp_precisionoption, so perhapstimestamp_zoneoption would fit nicely. This could be set to:browser,:application, or a specific time zone string. Setting it to:browserwould add adata-behaviorattribute to the underlying<time>element allowing the JS to take over. Fallback content would probably still be provided using the application's time zone. -
I would have no objection to
:browserbeing the default setting for the above configuration option. -
These settings could be potentially be overridden by passing the
:zoneoption to thetimestampordatestamphelpers.
Hello. I am also interested in solving this problem. Have you already managed to do something in this direction? Best
Hello. I am also interested in solving this problem. Have you already managed to do something in this direction? Best
I didn't find time to work on this. Please feel free to take it on.