I spend a lot of time trying everything the javadocs and the forum posts advice. No matter what I did I couldn't make this work. I have to show to my application dates that can be into a DST or non DST enabled period. The smartGWT components seem to take abritrary decisiions as to when to apply DST adjustment or when not!
I include the following test case, which will use to open a ticket as well. I am using latest svn code for smartgwt (rev 1108), gwt 2.0.3 and tested it on Linux FF 3.5.8 and Chrome 5.0.360.0 dev and Windows IE 8.
As it is clear from the attached pic and the code, there are two dates (first is in a non DST enabled time and the other in a DST enabled one). The DateTimeItem correctly displays them when date formatter is the TOSTRING provided one. The format is not what I want but at least the data are displayed correctly!
Next using the TOEUROPEANSHORTDATETIME date formatter I get a the format closer to my liking, but the data are incorrectly displayed. The DateTimeItem now decides it is a good time to make a DST adjustment.
IMO the way the TOSTRING is handling the data is the right one. But the fact that I can't control the format is very annoying. Also trying to use the DateUtil to override the format with a custom one was unsuccessful - although I used exactly the code you provide at your javadocs. How can anyone achieve a uniform and customizable view of the date data in smartGWT?
I include the following test case, which will use to open a ticket as well. I am using latest svn code for smartgwt (rev 1108), gwt 2.0.3 and tested it on Linux FF 3.5.8 and Chrome 5.0.360.0 dev and Windows IE 8.
Code:
package com.ghost277.smartgwt.testcases.client.datetimeTest; import java.util.Date; import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.TimeZone; import com.google.gwt.i18n.client.constants.TimeZoneConstants; import com.smartgwt.client.types.DateDisplayFormat; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.DateTimeItem; public class DateTimeTest implements EntryPoint { /** * Date Time Test class to test DST and other time transforms. */ /* (non-Javadoc) * @see com.google.gwt.core.client.EntryPoint#onModuleLoad() */ public void onModuleLoad() { final TimeZoneConstants timeZoneConstants = GWT.create(TimeZoneConstants.class); DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy.MM.dd HH:mm:ss v"); //Date is not in DST period. String myDate = "2010.03.25 01:00:00 GMT"; Date date = dtf.parse(myDate); //Date is in DST period for my zone. String myDate2 = "2010.03.29 01:00:00 GMT"; Date date2 = dtf.parse(myDate2); TimeZone utcTz = TimeZone.createTimeZone(0); TimeZone athensTz = TimeZone.createTimeZone(timeZoneConstants.europeAthens()); DateTimeFormat dtf2 = DateTimeFormat.getFullDateTimeFormat(); Log.debug("Date1 in UTC: " + dtf2.format(date, utcTz)); Log.debug("Is DST date in UTC: " + utcTz.isDaylightTime(date)); Log.debug("Date1 in Athens: " + dtf2.format(date, athensTz)); Log.debug("Is DST date in Athens: " + athensTz.isDaylightTime(date)); Log.debug("Date2 in UTC: " + dtf2.format(date2, utcTz)); Log.debug("Is DST date in UTC: " + utcTz.isDaylightTime(date2)); Log.debug("Date2 in Athens: " + dtf2.format(date2, athensTz)); Log.debug("Is DST date in Athens: " + athensTz.isDaylightTime(date2)); DynamicForm form = new DynamicForm(); //Dates displays correct - format is not what we want. DateDisplayFormat dsf = DateDisplayFormat.TOSTRING; DateTimeItem dateItem = new DateTimeItem(); dateItem.setWidth(300); dateItem.setDateFormatter(dsf); dateItem.setName("Date"); dateItem.setValue(date); DateTimeItem dateItem2 = new DateTimeItem(); dateItem2.setDateFormatter(dsf); dateItem2.setWidth(300); dateItem2.setName("Date2"); dateItem2.setValue(date2); //Date displays wrong - format is closer to what we want. dsf = DateDisplayFormat.TOEUROPEANSHORTDATETIME; DateTimeItem dateItem3 = new DateTimeItem(); dateItem3.setDateFormatter(dsf); dateItem3.setWidth(300); dateItem3.setName("Date3"); dateItem3.setValue(date); DateTimeItem dateItem4 = new DateTimeItem(); dateItem4.setDateFormatter(dsf); dateItem4.setWidth(300); dateItem4.setName("Date4"); dateItem4.setValue(date2); form.setItems(dateItem, dateItem2, dateItem3, dateItem4); form.show(); } }
Next using the TOEUROPEANSHORTDATETIME date formatter I get a the format closer to my liking, but the data are incorrectly displayed. The DateTimeItem now decides it is a good time to make a DST adjustment.
IMO the way the TOSTRING is handling the data is the right one. But the fact that I can't control the format is very annoying. Also trying to use the DateUtil to override the format with a custom one was unsuccessful - although I used exactly the code you provide at your javadocs. How can anyone achieve a uniform and customizable view of the date data in smartGWT?
Comment