Using the same test case from the earlier DateTime equals Today problem, we discovered that if the Server is in say America/New York timezone (GMT-4) and the client machine is in America/Los Angeles (GMT-7) and we issue the call
The the filter for equals Today is actually evaluating to Yesterday and not to Today.
See attached screenshots from 2 clients, you will see the current time on there as well.
To reproduce, run server in GMT-4 timezone (America/New York), run client machine on GMT-7 (America/Los Angeles). Select DateTime filtter of equals Today, click filter.
Code:
DateUtil.setDefaultDisplayTimezone("-04:00");
See attached screenshots from 2 clients, you will see the current time on there as well.
To reproduce, run server in GMT-4 timezone (America/New York), run client machine on GMT-7 (America/Los Angeles). Select DateTime filtter of equals Today, click filter.
Code:
public class DateTimeTest2 implements EntryPoint { public static final long MILLISECONDS_IN_A_SECOND = 1000; public static final long MILLISECONDS_IN_A_MINUTE = MILLISECONDS_IN_A_SECOND * 60L; public static final long MILLISECONDS_IN_A_HOUR = MILLISECONDS_IN_A_MINUTE * 60L; public static final long MILLISECONDS_IN_A_DAY = MILLISECONDS_IN_A_HOUR * 24L; DataSource dataSource; ListGrid grid; int counter = 0; ListGridRecord[] cacheData = new ListGridRecord[8]; public static final String fpk = "ID"; public static final String sf1 = "String_Field"; public static final String df2 = "Date_Field"; public static final String dtf3 = "Date_Time_Field"; private void loadData(int size) { cacheData = new ListGridRecord[size]; long now = System.currentTimeMillis(); long threeDaysInPast = now - ((size / 4) * MILLISECONDS_IN_A_DAY); Date d = new Date(threeDaysInPast); for (int i = 0; i < cacheData.length; i++) { cacheData[i] = new ListGridRecord(); cacheData[i].setAttribute(fpk, i); cacheData[i].setAttribute(sf1, "abc-" + i); cacheData[i].setAttribute(df2, d); cacheData[i].setAttribute(dtf3, d); d = new Date(d.getTime() + (10 * MILLISECONDS_IN_A_HOUR)); } } @Override public void onModuleLoad() { DateUtil.setDefaultDisplayTimezone("-04:00"); final VLayout appLayout = new VLayout(); appLayout.setWidth100(); appLayout.setHeight100(); loadData(24); buildDataSource(); buildGrid(); final FilterBuilder fb = new FilterBuilder(); fb.setTopOperatorAppearance(TopOperatorAppearance.RADIO); fb.setTopOperator(LogicalOperator.AND); fb.setShowModeSwitcher(Boolean.FALSE); fb.setDataSource(dataSource); IButton filterButton = new IButton("Filter"); filterButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { AdvancedCriteria criteria = fb.getCriteria(); Criteria resolvedCriteria = dataSource.convertRelativeDates(criteria); JSONEncoder encoder = new JSONEncoder(); encoder.setDateFormat(JSONDateFormat.LOGICAL_DATE_CONSTRUCTOR); String textCriteria = encoder.encode(resolvedCriteria.getJsObj()); SC.say(textCriteria); grid.filterData(criteria); } }); IButton reloadButton = new IButton("Reload"); reloadButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { grid.invalidateCache(); } }); appLayout.setMargin(5); appLayout.setMembersMargin(5); Label currentTime = new Label((new Date()).toString()); currentTime.setHeight(50); appLayout.addMembers(currentTime, fb, filterButton, reloadButton, grid); appLayout.draw(); } private void buildGrid() { grid = new ListGrid(); grid.setDataFetchMode(FetchMode.PAGED); grid.setTitle("Test Grid"); grid.setAutoFetchData(true); grid.setAutoFitFieldsFillViewport(Boolean.TRUE); grid.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH); grid.setAutoFitFieldWidths(Boolean.TRUE); grid.setCanFreezeFields(Boolean.FALSE); grid.setCanGroupBy(Boolean.FALSE); grid.setRecordComponentPoolingMode(RecordComponentPoolingMode.RECYCLE); grid.setAlternateRecordStyles(Boolean.TRUE); grid.setHeight100(); grid.setWidth100(); ListGridField gfld1 = new ListGridField(sf1, "String Field"); ListGridField gfld2 = new ListGridField(df2, "Date Field"); ListGridField gfld3 = new ListGridField(dtf3, "DateTime Field"); grid.setFields(gfld3, gfld2, gfld1); grid.setDataSource(dataSource, grid.getAllFields()); } private void buildDataSource() { dataSource = new DataSource(); dataSource.setClientOnly(true); DataSourceField fldId = new DataSourceField(fpk, FieldType.INTEGER); fldId.setPrimaryKey(true); DataSourceField fld1 = new DataSourceField(sf1, FieldType.TEXT); DataSourceField fld2 = new DataSourceField(df2, FieldType.DATE); DataSourceField fld3 = new DataSourceField(dtf3, FieldType.DATETIME); dataSource.setFields(fldId, fld1, fld2, fld3); dataSource.setCacheData(cacheData); } }
Comment