Announcement

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

    Need some guidance on setDefaultDisplayTimezone()

    Hi, i'm currently looking into enabling uses to configure local timezone in case they're travelling abroad.

    I tried the abovementioned call and it seems to work, but i have some issues.

    1. From what i can see from the smartclient docs, this is *only* supported for datetime fields? What about time fields, is there any way to leverage this functionality for that type of field?


    2. i have some places where i have a custom cellformatter on the datetimefield, for example:
    Code:
    public class WPOutTimeFormatter implements CellFormatter {
    
        @Override
        public String format(Object value, ListGridRecord record, int i, int i1) {
            if (value != null) {
                GWT.log("the date i got in is " + value);
                return DateUtils.lengthWithPlusDates(record.getAttributeAsDate(CSConstants.FIELD_INTIME), (Date) value);
            }
            return "";
        }
    The problem is that the Date value that comes in the value Object is the 'regular' date. Is there any way to have a custom formatter like this but make it work with a custom timezone?

    Help appreciated.

    #2
    1. It works for both time and datetime

    2. Changing the display timezone does not change the underlying date value (that would be a bug!). The formatters we provide will use the configured display timezone, and since we support SimpleDateFormat, you can probably get whatever you want out of those. Or just use GWT's DateTimeFormat, which also supports being given a timezone.

    Comment


      #3
      1. That's great, thanks! (The smartclient docs on Time.setDefaultTimeZone says "Sets the offset from UTC to use when formatting values of type datetime with standard display formatters.Sets the offset from UTC to use when formatting values of type datetime with standard display formatters." - not complaining, just that it was enough to confuse me, as evidenced. Not that it takes much...)

      2. Perhaps you'll allow me to give you my usecase and see if you have any tips?

      The use case is to, in a listgrid that shows "workperiods" with an in- and outtime. I show intime with a standard date formatter, but for the outtime, which also is a datetime, i have a calculation that shows the out time as "09:00" for example if same day, but "09:00 (+1 day)" if it's x days later

      i have of course solved this with a cell formatter as you see in my example, where i put it on the "out" field, but i also need the "in" field which i then get with getattributeasdate, and call the function
      Code:
      public static String lengthWithPlusDates(Date inTime, Date outTime){
              int daysBetween = CalendarUtil.getDaysBetween(inTime, outTime);
              String plusdates = daysBetween > 0 ? " (+" + daysBetween + "d)" : "";
              return formatTimeDisplay(outTime) + plusdates;
          }
      So, do you have any tips on how to achieve this? I have other places where i have simular situations with cell formatters. Is my only choice to get the raw values out and do tons of timezone-calculations myself?

      Comment


        #4
        1. Sorry, we went to update the docs and realized we misspoke - the docs are already correct, and timezone offset does not apply to the "time" type because it is a logical time, like "all Hyatt hotels serve breakfast at 9am".

        2. This is a pretty run-of-the-mill coding exercise - we would recommend using AI to generate the code if you're having trouble.

        Comment

        Working...
        X