Announcement

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

    RelativeDateItem Represent Local and GMT Time

    Is it possible to have the RelativeDateItem display time in local time in the picklist/dropdown and GMT time in the calculatedDateField to the right of the drop down? I know SmartGWT uses the local time, but I would like to display both. Meaning, the user edits the time in local time, but the 'preview' displays it in GMT time in the calculatedDateField to the right.

    How would I do this? Can I use the DateUtil class to set a different format for the calculatedDateField than the text entry?
    Last edited by bwilkins30; 27 Feb 2013, 08:22.

    #2
    Here is the solution I developed.. maybe its a little hackish, but it works. DateFields is an enum. In my case, I have two relative date items that I concerned about and I figured out that the drop-down is formatted first in both and then the calculated date field.

    Code:
    /**
        * This method will make a system-wide change to the date display format for all SmartGWT
        * components. Has to be called before DateRangeItem is instantiated.
        * Note: You need a custom parser here or onChanged events won't fire!
        */
       private void changeDateFormat()
       {
    
          DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter()
          {
             @Override
             public String format(Date date)
             {
                if(date == null)
                {
                   return null;
                }
                else
                {
                   if (dateFields == DateFields.FIELD1_NO_UTC)
                   {
                      dateFields = DateFields.FIELD2_NO_UTC;
                      final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
                      String format = dateFormatter.format(date);                  
                      return format;
                   }
    
                   if (dateFields == DateFields.FIELD2_NO_UTC)
                   {
                      dateFields = DateFields.FIELD3_UTC;
                      final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
                      String format = dateFormatter.format(date);
                      return format;
                   }
    
                   if (dateFields == DateFields.FIELD3_UTC)
                   {
                      dateFields = DateFields.FIELD4_UTC;
                      final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT_W_ZONE);
                      String format = dateFormatter.format(date, TimeZone.createTimeZone(0));
                      return format;
                   }
                   else
                   {                  
                      final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT_W_ZONE);
                      String format = dateFormatter.format(date, TimeZone.createTimeZone(0));
                      dateFields = DateFields.FIELD1_NO_UTC;
                      return format;
                   }
                                                 
                }
    
             }
          });
    
          // It is a requirement that we implement a custom date parser or the onChanged event
          // will not fire.
    
          DateUtil.setDateParser(new DateParser()
          {
             @Override
             public Date parse(String dateString)
             {
                if (dateFields == DateFields.FIELD3_UTC || dateFields == DateFields.FIELD4_UTC)
                {
                   dateFields = DateFields.FIELD1_NO_UTC;
                }
                
                if (dateFields == DateFields.FIELD2_NO_UTC)
                {
                   final DateTimeFormat format = DateTimeFormat.getFormat(DATE_FORMAT);
                   dateFields = DateFields.FIELD3_UTC;
                   return format.parse(dateString);
                }
                else
                {
                   final DateTimeFormat format = DateTimeFormat.getFormat(DATE_FORMAT);
                   Date preFinalDate = format.parse(dateString);
                   final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT_W_ZONE);
                   String finalDateString = dateFormatter.format(preFinalDate, TimeZone.createTimeZone(0));
                   
                   Date finalDate = dateFormatter.parse(finalDateString);
    
                   dateFields = DateFields.FIELD4_UTC;
                   return finalDate;
                }
             }
          });
       }

    Comment


      #3
      I am looking to do something like this as well, aka format the input display differently from the calculated field display.

      What is the dateFields variable and the DateFields class?

      Comment


        #4
        Originally posted by stonebranch1 View Post
        I am looking to do something like this as well, aka format the input display differently from the calculated field display.

        What is the dateFields variable and the DateFields class?
        It's an enum.

        But I ended up scrapping that idea.

        See the code here: http://forums.smartclient.com/showthread.php?t=25568

        I hid the default "calculated date field", added a label off to the side of the RelativeDateItem. Every time the selection changed in the RelativeDateItem, I would change the value in the "calculated date field" to be formatted to UTC. This is done in the Start and End ChangedHandler.

        You can search the forums under my username for all the posts having to do with this from last March.

        Comment

        Working...
        X