I know that there's quite a lot of gems that do the job, but I think it's quite excessive to use a whole gem for such an easy task.
I found that js does it pretty easy:
Intl.DateTimeFormat().resolvedOptions().timeZone
The answer is a string like "Europe/Moscow"
.
We can easily save it to db
create_table :users do |t|
t.string :time_zone, default: "UTC"
...
end
and set user's time zone like:
# app/controllers/application_controller.rb
around_action :set_time_zone, if: :current_user
private
def set_time_zone(&block)
Time.use_zone(current_user.time_zone, &block)
end
So my question is: Am I missing something important (why these gems are being used) or I can do it like I wrote above (without any gems)?
Inspired by the ThoughtBot's article and this question