Forum: Ruby on Rails Best way to handle different time zones?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
00a7b73fc00362808cfa1dcaa5968efe?d=identicon&s=25 Justin Bailey (Guest)
on 2006-06-02 20:10
(Received via mailing list)
We have a project that is hosted in one time zone (say, Pacific Daylight
Time) but the client wants all time recorded in their time zone (say,
Mountain Time). What is the best way to do this? Any recommendations?
Thanks!

Justin
C9c7a65848f13e2b1a226bbe43bc3672?d=identicon&s=25 Pete Yandell (pete)
on 2006-06-03 01:23
(Received via mailing list)
On 03/06/2006, at 4:08 AM, Justin Bailey wrote:

> We have a project that is hosted in one time zone (say, Pacific
> Daylight Time) but the client wants all time recorded in their time
> zone (say, Mountain Time). What is the best way to do this? Any
> recommendations? Thanks!

Storing time in the database in a zone other than the server's zone
or UTC is difficult. You probably want to store all times as UTC, and
then convert them to the appropriate zone on output.

In environment.rb, you'll need:

   config.active_record.default_timezone = :utc

And then take a look at TZInfo (http://tzinfo.rubyforge.org/) for
doing timezone conversions.

Cheers,

Pete Yandell
http://9cays.com/
16b26104470ae1b64958f3caa836c193?d=identicon&s=25 Danny Burkes (dburkes)
on 2006-06-03 01:42
> Storing time in the database in a zone other than the server's zone
> or UTC is difficult. You probably want to store all times as UTC, and
> then convert them to the appropriate zone on output.
>

An approach that has worked well for me is to store all times in UTC,
build HTML pages in UTC, then use Javascript on the client side to
convert all the times to browser-local time before display.

cf. http://mikewest.org/archive/showing-perfect-time-u...

Regards,

Danny
573b9499030e1ccb867ef80f0ff1ac49?d=identicon&s=25 Justin Bailey (Guest)
on 2006-06-03 20:15
(Received via mailing list)
These are great answers. Thanks for your help, both of you!
This topic is locked and can not be replied to.