I have a customized GWT Date -Time widget which is a combination of two text boxes, one to hold the date and one to hold time. When I enter the date 04/09/1956 12:00 AM (in the Date widget), internally in the ValueChangeHandler for my widget I run it through the GWT's DateTimeFormat class' format() method which takes in the date and time zone information and gives me a formatted Date String that is User friendly when displayed and then based on the date in that widget, I set the time in the Time part of it.
The issue is when I put in dates not too old (my observation was dates not older than those in the year 1981), there seems to be no problem at all. When I put in dates older than that say 1956 in my case, there is some weird Daylight savings logic that messes my format of my string by adjusting it back by 1 hour and gives me 04/08/1956 11:00 PM instead of 04/09/1956 12:00 AM. Even though the date object still represents the date I intended to, the formatted string is messed up with a different date representation.
This is issue is reproducible only when I run the app in production mode. When I run it locally on my machine in the hosted mode, I do not see this problem at all. That is the worst part.
I understand that GWT reads from a javascript file called noCache.js when we run in production mode as opposed to the Web-INF/lib folder in hosted mode.
Also, I run the java.util.Date object through GWT's formatter in several other places where I have a date in hand but never have this issue..... It comes when I run it in a ValueChangeHandler.
Did any one encounter this weird behavior before?
OK. Here is the sample code:
Date date = new Date();
date.setYear(1956 - 1900);
date.setMonth(3);
date.setDate(9);
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
// date here is 04/09/1956 12:00 AM
DateTimeFormat dateTimeFormat = new DateTimeFormat(somePattern); //pattern is a string //which represents which pattern you want to use
String formattedDateString = dateTimeFormat.format(date, timeZone); // timeZone is an //instance of com.google.gwt.i18n.client.TimeZone
// formattedDateString is 04/8/1956 11:00 PM. The time got pushed back by one hour.