Saturday, September 4, 2010

Working with TimeZones

import java.util.TimeZone;

def tz = TimeZone.getTimeZone("Asia/Kuala_Lumpur")
def date = new Date();
def time = date.getTime()+tz.getOffset(date.getTime())
date.setTime(time)

In GAE:

Wrap the above in a method to bypass Reflections which GAE doesn't support

TimeZone.getAvailableIDs() also doesn't work in GAE because of Reflections

Correction, below works

public Date getDateWithTimeZone(Date date, String timeZone){
def tz = TimeZone.getTimeZone(timeZone);
def cal = Calendar.getInstance()
cal.setTimeInMillis( date.getTime() )
cal.setTimeZone( tz )
def offset = cal.get(Calendar.ZONE_OFFSET)
date.setTime( date.getTime()+offset )
return date;
}

Wednesday, September 1, 2010

Localization i18n for Grails and App Engine

Getting localization working on Grails on GAE
see below for workaround

checkout this jira:
http://jira.codehaus.org/browse/GRAILSPLUGINS-1905