Announcement

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

    Date and Timezone confusion

    Hi,
    I've some trouble sending correct dates to the server. Our server expects dates like 2009-01-07 (in XML). If there is some timecode behind, it is ignored.

    Now I've some DataSources containing DataSourceDateField. These fields are displayed and edited in ListGrids using a DateItem as editor.

    When I set 2009-01-07 in the grid, 2009-01-06T23:00:00 is send the server. 2009-01-07Txx:xx:xx would be fine.

    When I create a java.util.Data object on the client and call getTimezoneOffset, I get "-60" - I guess, that's the problem.

    How can I send the correct date to the server? Can I globally set the timezone?

    Thanks & kind regards
    Thilo

    #2
    Set the field as type:"date" and the time will be omitted when saving to the server.

    Comment


      #3
      Hi,
      thank your very much for your answer. But were to set this? In the grid or the datasource?

      That's my grid's field:
      Code:
      ListGridField fieldStartDate = new ListGridField(PeriodsDS.FIELDNAME_STARTDATE);
      fieldStartDate.setType(ListGridFieldType.DATE);
      fieldStartDate.setCanEdit(true);
      fieldStartDate.setRequired(true);
      fieldStartDate.setAlign(Alignment.CENTER);
      fieldStartDate.setTitle(appCtrl.getAppMessages().periodStart());
      
      DateItem startDateItem = new DateItem();  
      startDateItem.setUseTextField(false);  
      fieldStartDate.setEditorType(startDateItem);  
      fieldStartDate.setWidth(DATE_WIDTH);
      And that's my datasource's field:
      Code:
      DataSourceDateField startDateField = new DataSourceDateField(FIELDNAME_STARTDATE);
      startDateField.setType(FieldType.DATE);
      Thanks & best regards
      Thilo

      Comment


        #4
        That part looks fine. Try making a standalone test case and you should discover the problem.

        Comment


          #5
          Hi,
          I searched and tested a bit more and found the problem:
          We use a Grid and an according DataSource. But on sending to the server, we use another DataSource containing the others records as nested records.

          So, we do something like this:
          Code:
          DynamicForm form = new DynamicForm();
          form.setDataSource(ds1);
          form.setValue("field1", grid.getRecords());
          Now, grid's records contain dates and these are send as dates containing time information.

          We helped ourselves by converting the date fields to strings before sending.

          Thanks & kind regards
          Thilo

          Comment


            #6
            That, too, is automatic. Just make sure you have a DataSource for the nested records, and that the parent DataSource has a field whose type is set to the DataSource for the nested records.

            Comment


              #7
              Hi, thilo
              Have you solve this issue?
              I encountered the same problem.
              Would you like to give any hint or your solution to solve this issue?
              Thank you very much.

              Originally posted by thilo
              Hi,
              I've some trouble sending correct dates to the server. Our server expects dates like 2009-01-07 (in XML). If there is some timecode behind, it is ignored.

              Now I've some DataSources containing DataSourceDateField. These fields are displayed and edited in ListGrids using a DateItem as editor.

              When I set 2009-01-07 in the grid, 2009-01-06T23:00:00 is send the server. 2009-01-07Txx:xx:xx would be fine.

              When I create a java.util.Data object on the client and call getTimezoneOffset, I get "-60" - I guess, that's the problem.

              How can I send the correct date to the server? Can I globally set the timezone?

              Thanks & kind regards
              Thilo

              Comment


                #8
                DateUtil.setDefaultDisplayTimezone("00:00");

                Comment


                  #9
                  Thanks very much for your reply.

                  No matter using DateUtil.setDefaultDisplayTimezone("00:00") or not. I can get the user's input value 2009-11-26 00:00 by DateItem.getValue() in the client side. Howerver, the server side get 2009-11-25 16:00(user's browser is in +08:00 time zone) when submit to the server by ValuesManager.save().

                  How can I get the user's input(such as 2009-11-26)?
                  Any hint is appreciated.

                  SmartGWT 1.3
                  Browser: FF 3.5
                  OS: Windows XP SP3


                  Originally posted by mhulsman
                  DateUtil.setDefaultDisplayTimezone("00:00");

                  Comment

                  Working...
                  X