date incompatibility between GWT java.util.Date class and the javascript Date

422 views
Skip to first unread message

costa

unread,
Aug 31, 2009, 9:14:23 PM8/31/09
to Google Web Toolkit
Hello:

I came across this weird bug where I had code that created a
java.util.Date based on the value returned by the javascript
Date.getTime method.

Example:

Javascript (IE 7, FF 3.5): new Date(2002, 02, 20) is: Wed Mar 20 2002
00:00:00 PDT 2002
Java: new Date(102, 02, 20) is: Wed Mar 20 00:00:00 PST 2002

Note the time zone. This makes the GWT java.util.Date <-> JavaScript
Date interchange via the number of milliseconds since 1970 unreliable.

Any thoughts about this?

costa

unread,
Aug 31, 2009, 10:54:10 PM8/31/09
to Google Web Toolkit
It turns out that the problems that I am having stem from the way the
daylight savings time dates are calculated in the browser vs. java.

Here is a link with the US & Canada DST periods:
http://www.timeanddate.com/news/time/us-daylight-saving-extended.html

For instance in 2005 the daylight savings time in Vancouver BC started
on Apr 3rd. In 2010 the DST will start on Mar 14th.


Any java.util.Date object created in the browser (compiled code: java -
> javascript) that is between 14th of Mar 2005 and Apr 3rd 2005 will
have the time portion on the java side 23:00:00 because the browser
applies the next DST period to these dates. In the host mode the dates
work as expected because probably java uses time zone tables but as
soon as the code gets compiled to javascript things are not the same
in IE7.

I created a test remote service with the following method:

public void displayDate(Date date)
{
log.error("My date is " + date);
}

the Date object is a java.util.Date.

I created this client function:

private void displayDate(final Date date)
{
AsyncCallbackAdapter<Void> o = new AsyncCallbackAdapter<Void>()
{
@Override
public void executeImpl()
{
TestService.App.getInstance().displayDate(date, this);
}

};

o.execute();
}

Now the following code:
displayDate(new Date(105, 2, 13));
displayDate(new Date(105, 2, 14));
displayDate(new Date(105, 3, 3));
displayDate(new Date(105, 3, 4));

produces (on the server) in hosted mode:

My date is Sun Mar 13 00:00:00 PST 2005
My date is Mon Mar 14 00:00:00 PST 2005
My date is Sat Apr 02 00:00:00 PST 2005
My date is Sun Apr 03 00:00:00 PST 2005

and in web mode it produces:

My date is Sun Mar 13 00:00:00 PST 2005
My date is Sun Mar 13 23:00:00 PST 2005
My date is Sat Apr 02 23:00:00 PST 2005
My date is Mon Apr 04 00:00:00 PDT 2005

Note the time portion.



costa

unread,
Aug 31, 2009, 10:54:52 PM8/31/09
to Google Web Toolkit
I am using GWT 1.5

costa

unread,
Sep 1, 2009, 6:11:02 PM9/1/09
to Google Web Toolkit
Nobody there? Should I fill in a bug report? As it is right now I
don't think using java.util.Date to pass dates to a remote service is
reliable in the web mode and there can be very subtle bugs that are
hard to track.
Reply all
Reply to author
Forward
0 new messages