trestle icon indicating copy to clipboard operation
trestle copied to clipboard

Show timestamps in browser local timezone

Open swrobel opened this issue 5 years ago • 3 comments

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.

swrobel avatar Feb 18 '20 23:02 swrobel

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:

  1. The trestle-auth plugin has a config.auth.time_zone option 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

  2. I do think this should be configurable. There is currently a timestamp_precision option, so perhaps timestamp_zone option would fit nicely. This could be set to :browser, :application, or a specific time zone string. Setting it to :browser would add a data-behavior attribute to the underlying <time> element allowing the JS to take over. Fallback content would probably still be provided using the application's time zone.

  3. I would have no objection to :browser being the default setting for the above configuration option.

  4. These settings could be potentially be overridden by passing the :zone option to the timestamp or datestamp helpers.

spohlenz avatar Feb 24 '20 04:02 spohlenz

Hello. I am also interested in solving this problem. Have you already managed to do something in this direction? Best

maszuDEV avatar Jan 18 '22 23:01 maszuDEV

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.

swrobel avatar Jan 19 '22 00:01 swrobel