Announcement

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

    Editors and setDefaultDisplayTimezone show different times

    SGWTPro-2.5: SC_SNAPSHOT-2011-12-14/Pro Deployment 2011-12-14

    I'd like to be able to have all dates in UTC to avoid my application changing times when users access it in different timezones (eg, client time zone setting differs).

    This seems like a really common requirement. I wonder what is the best practice suggested by Isomorphic to implement consistent time/date rendering and ignore the client's timezone setting.

    Here is a test case. It shows that the FilterEditor and field with different times. When you click to edit the ListGrid record, the editor also shows a different time.

    The test time entered is Date(0). I presume that is 0:00 (midnight) at time zone 0:00. The filter editors show this time, however the ListGrid cell render does not.


    Code:
    	private void doTest() {
    		DateUtil.setDefaultDisplayTimezone("0:00");
    		DataSource ds = new DataSource();
    		ds.setClientOnly(true);
    		DataSourceField timeField = new DataSourceField("time", FieldType.TIME);
    		ds.setFields(timeField);
    		Record testRecord = new Record();
    		testRecord.setAttribute("time", new Date(0));
    		ds.setTestData(new Record[] { testRecord });
    
    		ListGrid listGrid = new ListGrid();
    		listGrid.setDataSource(ds);
    		listGrid.setShowFilterEditor(true);
    		Criteria dateCriteria = new Criteria();
    		dateCriteria.addCriteria("time", new Date(0));
    		listGrid.fetchData(dateCriteria);
    		listGrid.setCanEdit(true);
    		listGrid.show();
    	}

    #2
    When I type a value into the filter editor, then filter, it works as expected. It appears it is just the initial editor value format that does not take into account the timezone when I call fetchData.

    Comment


      #3
      Time fields are just logical times. They do not have a timezone as they are not on a particular date at all. Creating one via new Date() is not valid, use Time.parseInput().

      Comment


        #4
        I don't see the class Time in SmartGWT - presuming you meant that. There is DateUtils.parseInput() - perhaps this is equivalent?

        Certainly, things are fine if I call setAttribute("time","1:00pm"); And then I can go getAtrribute("time") and it returns "1:00pm".

        In my usage, I'm not actually trying to create dates using new Date(0). I was using that as a way to show the case I came across with less code.

        What I am trying to do is grab a Time value from a field, and then set a criteria using that value. So, I get the attribute from the time field, using getAttributeAsDate and then use that value to set the criteria.

        I tried getAttribute() which returns a string. On my data, this gives a full date ala Wed Dec 31 1969 08:00:00 GMT-0800 (PST). Presumably because in this case it is an actual JS date object because the JS code uses the method of storing new Date(xxxxx) to represent dates in the server response.

        What is the correct way to use a time field's value in a criteria?

        Comment

        Working...
        X