The problem is this code:

  Date date = new Date();
  date.setYear(Integer.valueOf(y) - 1900);
  date.setMonth(Integer.valueOf(m) - 1);
  date.setDate(Integer.valueOf(d));

You found this bug when you ran it yesterday, October 31st. That's
pertinent because the first line above creates a new date at today's date.
So the date is 2013-10-31 after constructing the date.

You then set the year to 2013, which doesn't actually do anything in this
case because it was already set to 2013.

Then you set the month, and that's when you have a problem. You set the
month to November, which means that you now have a date that's 2013-11-31.
However, there are only 30 days in November, so this wraps around to
2013-12-01. Not unreasonable behaviour given what you asked of it.

FInally, you set the day of the month to 2, and so you get 2013-12-02.

You should be really careful when using the setYear(...), setMonth(...) or
setDate(...) methods on Date because of this kind of thing. They are
generally best avoided if you can. What you should have done instead is to
use a different Date constructor:

  Date date = new Date(Integer.valueOf(y) - 1900, Integer.valueOf(m) -
1, Integer.valueOf(d));
*
*
Paul

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to