Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Display of date is wrong!

    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.

    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();
    	}
    
    }
    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?
    Attached Files

    #2
    Please try the latest nightly.

    Sanjiv

    Comment


      #3
      Also note that timezone and daylightSavingsTime behavior can now be adjusted globally via DateUtils.setDefaultDisplayTimezone() and DateUtils.setAdjustForDST()

      Comment


        #4
        I have a similar problem, i have two dateitems in my form, both displayed as text, and they edit a record of already defined dates. I have to parse from one format to an other format and in debug everything goes smoothly and the diteformat is rightly read and rightly converted, but the displayed value is not the one passed to setDefaultValue of the dateitem. The code is as follow:

        dataTrade = new DateItem();
        dataTrade.setTitle(Nove.getInstance().getConstants().dataTrade());
        dataTrade.setName(RecordEditMovTitUploadDS.DATA_TRADE);
        dataTrade.setWidth(400);
        dataTrade.setAlign(Alignment.LEFT);
        dataTrade.setUseTextField(true);
        String dataT = movTitRecord.getAttribute(ListMovTitByValCodTitDetailDS.DATA_TRADE);
        DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss.SSS");
        Date dateTr = null;
        try{
        dateTr = dateTimeFormat.parse(dataT);
        } catch(IllegalArgumentException e){
        SC.say("Couldn't parse date");
        }
        DateTimeFormat dateTimeFormat2 = DateTimeFormat.getFormat("dd/MM/yyyy");
        String dateTra= dateTimeFormat2.format(dateTr);
        dataTrade.setDefaultValue(dateTra);

        dataValuta = new DateItem();
        dataValuta.setTitle(Nove.getInstance().getConstants().dataValuta());
        dataValuta.setName(RecordEditMovTitUploadDS.DATA_VALUTA);
        dataValuta.setWidth(400);
        dataValuta.setAlign(Alignment.LEFT);
        dataValuta.setUseTextField(true);
        String dataV = movTitRecord.getAttribute(ListMovTitByValCodTitDetailDS.DATA_VALUTA);
        Date dateVa = null;
        try{
        dateVa = dateTimeFormat.parse(dataV);
        } catch(IllegalArgumentException e){
        SC.say("Couldn't parse date");
        }
        String dateVal= dateTimeFormat2.format(dateVa);
        dataValuta.setDefaultValue(dateVal);

        Comment


          #5
          https://stackoverflow.com/questions/...cform-smartgwt

          Comment


            #6
            You are posting in a thread about a bug resolved 7 years ago. Your issue is not related.

            First, look at dataSourceField.format, which handles date formatting without needing calls like yours above.

            Second, look over the APIs on DateUtil and realize that your configured input format must match whatever your formatters are doing.

            If you still think there might be a framework issue here, *start a new thread*, and provide minimal, ready-to-run code demonstrating whatever behavior you think is a bug.

            Comment


              #7
              In my datasource:

              In my datasource:

              DataSourceTextField dataTrade = new DataSourceTextField(DATA_TRADE, "DATA TRADE");
              DataSourceTextField dataValuta = new DataSourceTextField(DATA_VALUTA, "DATA VALUTA");

              setFields( dataTrade, dataValuta, ...

              Comment


                #8
                Could you please give me just a hint of how the datasourcefield should be in order to format this date? Thanks a lot

                Comment


                  #9
                  Hello, did you see dataSourceField.format as Isomorphic wrote?
                  https://www.smartclient.com/smartgwt...a.lang.String-
                  and also https://www.smartclient.com/smartgwt...matString.html

                  Comment

                  Working...
                  X