Uploaded image for project: 'PUBLIC - Liferay Social Office Community Edition'
  1. PUBLIC - Liferay Social Office Community Edition
  2. SOS-2002

SO announcement entries are recorded with the user's timezone when displayimmediately is checked


    • Fix Priority:
    • Affects Portal Version/s:
      6.1.20 EE GA2


      In ee-6.1.x when displayimmediately is set, the entry is recorded with the user's timezone, however in AnnouncementLocalServiceImpl.checkEntries() now variable is defined using java's new Date() which doesn't consider that timezone.

      In AnnouncementsEntryLocalServiceImpl.addEntry() this code is responsible for this behavior:

      		Date displayDate = PortalUtil.getDate(
      			displayDateMonth, displayDateDay, displayDateYear, displayDateHour,
      			displayDateMinute, user.getTimeZone(),

      Unfortunately, we don't have any extra parameter which we can use whether this entry was added with the displayimmediately or not, so I can only thought of some workarounds, since API change is forbidden (due to backward compatibility reasons).

      On trunk there is a new API (the extra displayimmediately parameter) for this, so this issue shouldn't occur.

      I think this would be a workaround to 6.1.x:

      diff --git a/portlets/so-announcements-portlet/docroot/WEB-INF/src/com/liferay/so/announcements/portlet/AnnouncementsPortlet.java b/portlets/so-announcements-portlet/docroot/WEB-INF/src/com/liferay/so/announcements/portlet/AnnouncementsPortlet.java
      index 060a9d1..82e3a22 100644
      --- a/portlets/so-announcements-portlet/docroot/WEB-INF/src/com/liferay/so/announcements/portlet/AnnouncementsPortlet.java
      +++ b/portlets/so-announcements-portlet/docroot/WEB-INF/src/com/liferay/so/announcements/portlet/AnnouncementsPortlet.java
      @@ -28,6 +28,7 @@ import com.liferay.portal.kernel.util.CalendarFactoryUtil;
       import com.liferay.portal.kernel.util.GetterUtil;
       import com.liferay.portal.kernel.util.ParamUtil;
       import com.liferay.portal.kernel.util.WebKeys;
      +import com.liferay.portal.model.User;
       import com.liferay.portal.theme.ThemeDisplay;
       import com.liferay.portlet.announcements.EntryContentException;
       import com.liferay.portlet.announcements.EntryDisplayDateException;
      @@ -37,6 +38,7 @@ import com.liferay.portlet.announcements.EntryURLException;
       import com.liferay.portlet.announcements.service.AnnouncementsEntryServiceUtil;
       import java.util.Calendar;
      +import java.util.TimeZone;
       import javax.portlet.ActionRequest;
       import javax.portlet.ActionResponse;
      @@ -211,8 +213,15 @@ public class AnnouncementsPortlet extends MVCPortlet {
       			actionRequest, "displayImmediately");
       		if (displayImmediately) {
      +			User user = themeDisplay.getUser();
       			Calendar calendar = CalendarFactoryUtil.getCalendar();
      +			long offset = user.getTimeZone().getOffset(
      +				calendar.getTimeInMillis());
      +			calendar.add(Calendar.MILLISECOND, (int)offset);
       			calendar.add(Calendar.MINUTE, 1);
       			displayDateMonth = calendar.get(Calendar.MONTH);




            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created:
                Days since last comment:
                6 years, 7 weeks, 3 days ago


                Version Package
                2.1.X EE