On Jun 24, 3:49 pm, Rakesh Arora <li...@ruby-forum.com> 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.

COPY/PASTE
------------------------------------------------
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:

# to convert posted date/time to UTC and save to DB
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

# to display date/time in a view
def utc2user(t)
     ENV["TZ"] = current_user.time_zone_name
     res = t.getlocal
     ENV["TZ"] = "UTC"
     res
end

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to