Grails Multiple Time Zone App

What is the correct way to handle time zones in a grails application that has users in multiple time zones? Is there a standard aproach to muilt timezone Grails app? Maybe there is something similar to how Rails handles multiple timezone support? http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/

Is there a way to set the current time zone for a user session? This would mean that you could have several active user sessions with different time zones used to work with Date.

I am trying to avoid having to manually handle timezone calls.

thanks

+4
source share
2 answers

Firstly, it is often useful to present the user with a choice - what time zone he is. You can try to make a conclusion from its settings, but this is unreliable. In grails, you can let the user select their time zone:

<g:timeZoneSelect name="myTimeZone" /> 

Note that the default value attribute matches the current Locale . So, I would suggest that, by default, the grails localeresolver function will do an excellent job of guessing the user's locale.

To do this, you need to store all the time in the database in UTC (or another time zone, which is fixed for the entire application)

The <g:formatDate> says that it has only 3 attributes, but at least version 1.2 seems to support the timeZone attribute. Therefore, you will need to set timeZone="${currentUser.timeZone}"

+2
source

You can try using JodaTime and the DateTime class, it has a timezone inside. However, I believe that you will need to store time in UTC. To do this, you need to provide your own GORM mapping, which uses UTC, a custom taglib for date formatting, which takes into account the user's time zone and some other things.

OTOH, if you have common features like background jobs (I suppose you will), what time zone will it use?

0
source

All Articles