Announcement

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

    6.1p: Problem with createLogicalDate creating bogus dates 1 to 6 days off expected date

    Hi Isomorphic,

    I have been using your advice from here to create a clientOnly-DataSource for my SelectItem using createLogicalDate() (please note that the value range is missing, compared to createLogicalTime()).

    By chance I saw today that the generated dates are completely wrong and can't be explained with DST, Timezones or similar, as I noted non-"last of month"-dates in my DB.
    If you agree this is an bug can you please tell me when this changed - because then I need to carefully adjust the data in the DB after you fix this issue.

    Please see this screenshot and the testcase (using 11.1p_2018-02-05):
    Click image for larger version

Name:	createLogicalDate Issue.PNG
Views:	88
Size:	35.9 KB
ID:	251644

    BuiltInDS.java:
    Code:
    package com.smartgwt.sample.client;
    
    import java.util.ArrayList;
    import java.util.Date;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.i18n.shared.DateTimeFormat;
    import com.smartgwt.client.Version;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.util.DateUtil;
    import com.smartgwt.client.util.LogicalDate;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS implements EntryPoint {
        private VLayout mainLayout;
        private IButton recreateBtn;
    
        public void onModuleLoad() {
            KeyIdentifier debugKey = new KeyIdentifier();
            debugKey.setCtrlKey(true);
            debugKey.setKeyName("D");
    
            Page.registerKey(debugKey, new PageKeyHandler() {
                public void execute(String keyName) {
                    SC.showConsole();
                }
            });
    
            mainLayout = new VLayout(20);
            mainLayout.setWidth100();
            mainLayout.setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    recreate();
                }
            });
            mainLayout.addMember(recreateBtn);
            recreate();
            mainLayout.draw();
        }
    
        private void recreate() {
            Window w = new Window();
            w.setWidth("25%");
            w.setHeight("65%");
            w.setMembersMargin(0);
            w.setModalMaskOpacity(70);
            w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
            w.setTitle("Severe problem with createLogicalDate" + w.getTitle());
            w.setShowMinimizeButton(false);
            w.setIsModal(true);
            w.setShowModalMask(true);
            w.centerInPage();
    
            final ListGrid testDataGrid = new ListGrid(getClientDataSource());
    
            ListGridField displayField = new ListGridField("displayField");
            ListGridField dateAsString = new ListGridField("dateAsString");
            ListGridField valueField = new ListGridField("valueField");
    
            testDataGrid.setFields(displayField, dateAsString, valueField);
            testDataGrid.fetchData();
            w.addItem(testDataGrid);
            w.show();
        }
    
        private static DataSource getClientDataSource() {
            DataSource ds = new DataSource();
            ds.setClientOnly(true);
            ds.setTitleField("displayField");
            DataSourceField valueField = new DataSourceField("valueField", FieldType.DATE);
            valueField.setPrimaryKey(true);
            DataSourceField displayField = new DataSourceField("displayField", FieldType.TEXT);
            DataSourceField dateAsStringField = new DataSourceField("dateAsString", FieldType.TEXT);
            ds.setFields(valueField, displayField, dateAsStringField);
    
            ArrayList<Record> recordList = new ArrayList<Record>();
    
            for (String s : new String[] { "December 2017/2017-12-31", "January 2018/2018-01-31", "February 2018/2018-02-28",
                    "March 2018/2018-03-31", "April 2018/2018-04-30", "May 2018/2018-05-31", "June 2018/2018-06-30", "July 2018/2018-07-31",
                    "August 2018/2018-08-31", "September 2018/2018-09-30", "October 2018/2018-10-31", "November 2018/2018-11-30",
                    "December 2018/2018-12-31", "January 2019/2019-01-31", "February 2019/2019-02-28", "March 2019/2019-03-31", "April 2019/2019-04-30",
                    "May 2019/2019-05-31", "June 2019/2019-06-30", "July 2019/2019-07-31", "August 2019/2019-08-31", "September 2019/2019-09-30",
                    "October 2019/2019-10-31", "November 2019/2019-11-30", "December 2019/2019-12-31" }) {
                String[] splitted = s.split("/");
                ListGridRecord lgr = new ListGridRecord();
                lgr.setAttribute("displayField", splitted[0]);
                lgr.setAttribute("dateAsString", splitted[1]);
                Date d = DateTimeFormat.getFormat("yyyy-MM-dd").parseStrict(splitted[1]);
                @SuppressWarnings("deprecation")
                LogicalDate ld = DateUtil.createLogicalDate(d.getYear() + 1900, d.getMonth() + 1, d.getDay());
                lgr.setAttribute("valueField", ld);
                recordList.add(lgr);
            }
            ds.setCacheData(recordList.toArray(new Record[recordList.size()]));
            return ds;
        }
    }
    This is an important one for me.

    Best regards
    Blama

    #2
    Hi Isomorphic,

    any feedback on this one? I'll move to a table-based approach soon (not only because of the bug), but then I'll still have to update the existing data in the DB and need a mapping here.

    Best regards
    Blama

    Comment


      #3
      Your code is calling getDay() rather than getDate()...

      Comment


        #4
        Hi Isomorphic,

        thanks a lot and sorry for the bogus report. Don't know if I should laugh or cry.
        At least this makes the fixing more easy.

        But could you nevertheless add documentation about allowed/expected values ranges for the parameters to createLogicalDate()?

        Best regards
        Blama

        Comment

        Working...
        X