Here is the entry in the environment.config to set the time_zone:
config/environment.rb
config.time_zone = ‘UTC’
Instead of setting this to a particular time zone, is it possible to set
this to the local time zone?
Thanks,
-Rakesh
Here is the entry in the environment.config to set the time_zone:
config.time_zone = ‘UTC’
Instead of setting this to a particular time zone, is it possible to set
this to the local time zone?
Thanks,
-Rakesh
On Jun 24, 3:49 pm, Rakesh A. [email protected] wrote:
Here is the entry in the environment.config to set the time_zone:
config/environment.rb
config.time_zone = ‘UTC’
Instead of setting this to a particular time zone, is it possible to set
this to the local time zone?
I don’t believe there is a way to set the local time zone in the
environment file.
Now, I’m reading a book on Rails that has a section about time zones
and it states that you can use a pure-Ruby gem called TZInfo with a
TimeZone class that correctly handles DST (Daylight Saving Time).
You’ll need to install both the tzinfo gem and the tzinfo_timezone
plugin, but it’s reportedly slow (it could be fast for whatever you’re
doing)
There’s also another solution, but for Mac users. I’m not sure if this
still works or not, but I’ll give you the code anyways and you can
play around with it.
You would add the following code to one of your application’s helper
modules or put it in tis own class within the lib folder:
def user2utc(t)
ENV[“TZ”] - current_user.time_zone_name
res = Time. local(t.year, t.month, t.day, t.hour, t.min,
t.sec).utc
ENV[“TZ”] = “UTC”
res
end
def utc2user(t)
ENV[“TZ”] = current_user.time_zone_name
res = t.getlocal
ENV[“TZ”] = “UTC”
res
end
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs