On Jul 13, 2011, at 10:53 AM, Bill Walton wrote:

Hi Ben,

On Wed, Jul 13, 2011 at 9:47 AM, Ben Perry <[email protected]> wrote:
I've got a javascript that provides me with the timezone for the
client. I want to use this to set Time.zone so that all my times
stored in the database are displayed in the timezone for the client.
So really simplistically

var timezone = jstz.determine_timezone().timezone
Time.zone = timezone.olson_tz

obviously this can't be done. I've taken a look on the web and can
only find 'solutions' over two years old and as ROR moves so fast I
thought someone may know of a better solution. So can anyone suggest a
simple solution?

It needs to be set on the server.  You could do an AJAX call.

Or, you could do this all in JavaScript, and simply translate the dates in the browser. Store -- and display -- one time zone, like UTC. But then on the client, collect all your dates (wrap them in a span.date or something that you can get using JS) and use the client's notion of the time zone to adjust their display on screen.

$$('span.date').each(function(elm){
        var d = new Date();
        var offset = d.getTimeZoneOffset() * 3600 * 1000;
        var adjusted = new Date(elm.innerHTML);
        adjusted.setTime(adjusted.getTime() + offset);
        elm.update(adjusted.toLocaleDateString());
});

Walter


HTH,
Bill

--
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- [email protected]. To unsubscribe from this group, send email to [email protected] . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en .


--
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to