Announcement

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

    DateUtil default formats and datetimes problem

    Hi,

    I've got some questions about date format handling.

    question 1:

    Should the DateUtil.setNormalDateDisplayFormatter and DateUtil.setShortDateDisplayFormatter work on datetime typed items too ? I'm trying to set the date display and date input formats to common european dot-separated formats ("dd.MM.yyyy HH:mm"). It seems that if I'm using DateTimeItems on forms and/or DataSourceDateTimeFields in data sources the display formats set by DateUtil just don't seem to apply.

    My observations:

    a) ListGrid + data source with DataSourceDateTimeField: does not work (uses always TOEUROPEANSHORTDATETIME instead of calling my custom formatter).

    b) ListGrid + data source with DataSourceDateField: works

    c) DynamicForm + DateItem + data source with DataSourceDateField: works

    d) DynamicForm + DateItem + data source with DataSourceDateTimeField: works

    e) DynamicForm + DateTimeItem + data source with DataSourceDateField: does not work (uses always TOEUROPEANSHORTDATETIME instead of calling my custom formatter).

    f) DynamicForm + DateTimeItem + data source with DataSourceDateTimeField: does not work (uses always TOEUROPEANSHORTDATETIME instead of calling my custom formatter).

    Sorry if these a bit hard to get a grip on but I couldn't get my head on the logic here. It seems like in case of ListGrids the data source field type is the factor here and with forms the the actual form items affect the behaviour.

    question 2:

    I'm calling DateUtil.setDefaultDisplayTimezone("00:00") to set the time zone to my liking. Strangely this time zone gets only applied to the smartgwt's default datedisplayformats (available in DateDisplayFormat enum). If I use a custom format as set as above (see question 1) it seems the time zone does not get applied. This leads to the incorrect times by three hours as the browser's (+3h) time zone gets applied.

    I'm using XML-based restdatasources and passing the dates as follows:
    ...
    <somedatetime>2010-04-11T17:33:06</somedatetime>
    ...

    What I really would like to do is to trust the server's time zone. What I mean above as I say time zone does not get applied I mean that when the server returns the 2010-04-11 17:33:06 date time the widgets render the time as 2010-04-11 20:33:06 (off by three hours). This does not happen if I don't set the custom formatter and use the default formats smartgwt sets up for me.

    I'm using smartgwt 2.1/lgpl, gwt-mac-2.0.3 and safari 4.0.5 for my testing. I've initialized the date formats as follows:

    Code:
        private static DateTimeFormat dateFormat = DateTimeFormat.getFormat("dd.MM.yyyy HH:mm");
    
        private static DateDisplayFormatter dateDisplayFormatter = new DateDisplayFormatter() {
            public String format(Date date) {
                if (date == null)
                    return null;
                return dateFormat.format(date);
            }
        };
    
        private static DateInputFormatter dateInputFormatter = new DateInputFormatter() {
            public Date parse(String s) {
                if (s == null)
                    return null;
                return dateFormat.parse(s);
            }
        };
    
        public void onModuleLoad() {
            DateUtil.setDefaultDisplayTimezone("00:00");
            // Set up date formats globally         
            DateUtil.setShortDateDisplayFormatter(dateDisplayFormatter);
            DateUtil.setNormalDateDisplayFormatter(dateDisplayFormatter);
            DateUtil.setDateInputFormatter(dateInputFormatter);
    
        //...
        }

    #2
    Anyone ?

    Could it be by design that DateUtil does not work with datetime -items/fields or ... something ?

    Comment


      #3
      Hi, was there a resolution to this thread? I'm using SmartGWT 2.2 and facing both issues that Markok raised.

      Is there a reason that DateUtil.setShortDateDisplayFormatter only works on date typed items and not also on datetime typed items? I also used DateUtil.setDefaultDisplayTimezone("00:00") to get past the second issue, but (like Markok said) this only works for datetime typed items. Time is still wrong for date typed items. A setting to trust the server's time zone would get past this.

      The combination of these 2 issues is a big problem. Datetime typed items have the right time but wrong format, while date typed items have the right format but the wrong time.

      Markok, were you able to figure this out? Thanks.

      Comment


        #4
        Any solution found for this?

        I am experiencing the same issue trying to use a DateTimeItem that is formatted based on the DateUtil formatters (normal, input, short,etc.)


        How about setting a custom formatter via DateTimeItem->setDisplayFormat, per the API you can pass in either a DateDisplayFormat type OR
        "or a function which will return a formatted date time string.". Does this custom function approach work? If so what interface should it implement?

        Comment


          #5
          I have the same problem, can get my date time formatted....
          Any solution finally ?
          thanks

          Comment


            #6
            I'm running into the same problem trying to set the date time format for a list grid column that's a datetime type. Any help?

            Comment


              #7
              kevboy you just posted elsewhere that you were using an ListGrid subclass with an overridden formatter. Same problem perhaps?

              Comment


                #8
                I'm sorry, to clarify: I can set the DatetimeFormatter for the list grid but I'd like to have it set for the whole application including forms, etc.

                Comment


                  #9
                  You apply system-wide default date, time and datetime formatters via the DateUtil class.

                  Comment


                    #10
                    I tried the following but it didn't work:
                    Code:
                            DateUtil.setNormalDateDisplayFormat(DateDisplayFormat.TOJAPANSHORTDATETIME);
                            DateUtil.setShortDateDisplayFormat(DateDisplayFormat.TOJAPANSHORTDATETIME);
                    SmartGWT 2.4 Power in IE7.

                    Comment


                      #11
                      So far, you are only calling APIs to affect the date display format, not the datetime display format, which is distinct.

                      Comment


                        #12
                        Oh yeah, you're right. I had forgot to mention I didn't see methods for setting date time defaults. Am I missing something?

                        Comment


                          #13
                          Grab 2.5 - there are now central datetime formatting functions, and it's probably a good time to upgrade anyway.

                          The alternative is needing to set these on a per-component basis.

                          Comment

                          Working...
                          X