tags:

views:

74

answers:

1

I have seen countless forum posts complaining of issues in GWT when handling dates. I am still very unclear as to what is "wrong" with the date handling, what special considerations need to be made, and when/where/why methods like Date.setMinutes(int minutes) should not be used.

Does anybody have feedback?

+2  A: 

Way back in the beginning of Java (i.e., Java 1.0), the date/time api largely (solely?) consisted of the Date class. The Java folks were aware that it lacked robustness, so they added the Calendar class in Java 1.1 and tried to change the Date class into a value object by deprecating most of it. Unfortunately, the Calendar class itself wasn't very well thought-out (see here) and we're stuck with what many consider to be a monstrosity.

Bringing us up to today, GWT supports Date because, well... how can you live without dates?, but doesn't support Calendar/GregorianCalendar/TimeZone because it's so ugly and surely there has to be a better answer. Sadly, no one's thought of it in over 3 years as Calendar support was requested way back in January of 2007 and marked as planned by April 2008.

In short, go ahead and use the the deprecated Date methods in your GWT code, if that will work for what you need to do.

Tony
Paweł Dyda
I have no doubt that it's extremely hard to get right. I listened to a podcast once where one of the Java api guys was going on about how hard it was to encapsulate the abstract notion of a calendar. He gave an example (IIRC) of the Thai having something like ten different calendars, where each has a different number of days in the week. It sounds like a very hard problem.
Tony