2
votes

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.
1
Interesting. Please post relevant code and outputs for assistance. - Chris Cashwell
I updated the question with some sample code.. Thanks for considering this. - Karthik
This could be a microsoft windows problem. There are some PCs that need their update sequence flushed out or OS re-installed fresh and their updates redone. Are you running on production mode on XP systems? Have you tried running across various other OS? Mac, Linux, Win 7? - Blessed Geek
In HostedMode GWT uses the timezone from your java vm, which can lead to a different behaviour with Dates when your application is forcing a different timezone e.g. GMT. - ocaner
And the result you mentioned could be correct based on the used timezone, please provide precise timezone informations, what timezone is used in your code sample and what is used on your system or app? - ocaner

1 Answers

1
votes

Windows suport Daylight saving from the year 1987. This is why any date before that year is not correctly shown. check it at Wikipedia