gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.51k stars 372 forks source link

DateBox getValue returns date minus one hour for specific dates #7642

Open dankurka opened 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 7645

Found in GWT Release (e.g. 2.4.0, 2.5.0 RC):

2.4.0

Encountered on OS / Browser (e.g. WinXP, IE8-9, FF7):

Win7, FF14, IE8

Detailed description:

A datebox is used to store to dates of birth in a database (implemented with the Editor
framework). In case the locale is set to German an hour is subtracted from the input
date for specific dates (before 1980). For example, if the input date is 14.04.1970
datebox getValue returns 13.04.1970 23:00:00.    

Shortest code snippet which demonstrates issue (please indicate where
actual result differs from expected result):

DateBox birthday;
birthday.setFormat(new DateBox.DefaultFormat (DateTimeFormat.getFormat("dd.MM.yyyy")));

Date birth = birthday.getValue(); 
//returns 13.04.1970 23:00:00 if input is 14.04.1970

Workaround if you have one:

add an hour to the date before saving

Date bd = birthday.getValue();
birthday.setFormat(new DateBox.DefaultFormat (DateTimeFormat.getFormat("dd.MM.yyyy
HH:mm:ss")));
birthday.setValue(new Date(bd.getTime()+(1000l*60l*60l )));

Links to relevant GWT Developer Forum posts:
https://groups.google.com/forum/#!topic/google-web-toolkit/e7IqbcJIzTY/discussion

Reported by stefanie.luipersbeck on 2012-09-03 16:54:51

dankurka commented 9 years ago
Perhaps it's just a problem about timezone of your server != browser. Date java object
always take the timezone of the JVM for serveur side and browser timezone for the client
side. You can't do anything about that. You can get each value (day, month..) and copy
them to a timezoned GregorianCalendar.

GregorianCalendar is not available is the gwt client side code so you should use String
for client/server communication to avoid any timezone problem.

Hope it helps

Reported by fabien.grenier@rtone.fr on 2013-10-25 11:52:28