Tuesday, March 29, 2011

ExtJS, Grails and dates

Recently I've been made aware of a problem with interoperability between ExtJS and Grails in regards to date serialization. Here's the deal:

1. Grails expects the date to be UTC
2. Grails expects the date to end with a 'Z' (denoting that it actually is UTC)
3. ExtJS by default when parsing date thinks just concatenates the year, month, day, hour, minutes and seconds and does no other processing.

To change this behavior and make it work across different time zones right out of the box simply provide the following implementation of Ext.util.JSON.encodeDate:
Ext.util.JSON.encodeDate = function(d) {
return d
.add(Date.MINUTE, d.getTimezoneOffset())

That's it when it comes to passing dates from client to server. More on serializing date on the server next time!

No comments: