tinny
tinny

Reputation: 4257

Grails application serving multiple timezones

What is the correct way to deal with timezones in a grails application that has users in multiple timezones? Is there a standard aproach to muilt timezone Grails applications? Maybe there is something simlar to the way Rails handles multi timezone support? http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/

Is there a way to set the current timezone per user session? This would mean you could have multiple active user sessions with different timezones being used for dealing with ”Date”.

Im trying to avoid having to manually deal with timezone conversions.

Thanks

Upvotes: 4

Views: 2613

Answers (2)

Victor Sergienko
Victor Sergienko

Reputation: 13475

You could try using JodaTime and DateTime class, it has timezone inside. Still, I believe you'll need to store times in UTС. For that, you'll have to provide own mapping to GORM that applies UTC, own date formatting taglib that takes into account user timezone, and some more things.

OTOH, if you have some common functionality, like background jobs (I believe you will), what time zone is it going to use?

Upvotes: 0

Bozho
Bozho

Reputation: 597016

First, it is often a good idea to present the user with a choice - which timezone he is in. You can try to infer it from his settings, but that's not reliable. In grails you can let the user select his timezone by:

<g:timeZoneSelect name="myTimeZone" />

Note that the value attribute defaults to the current Locale. So I'd guess grails' default localeresolver will do a fine job guessing the locale of the user.

For that to work you need to store all times in the DB in UTC (or another timezone which is fixed for the whole application)

The documentation of <g:formatDate> claims it has only 3 attributes, but it seems since at least version 1.2 it supports a timeZone attribute. So you'd have to put timeZone="${currentUser.timeZone}"

Upvotes: 2

Related Questions