Feature fixed timezone (#824)
* Fix typo * Set fixedTimeZone via properties * Fix Sonar findings * Fix review findings * Rename variable * Fix logic Signed-off-by: Jeroen Laverman <jeroen.laverman@bosch-si.com>
This commit is contained in:
committed by
Stefan Behl
parent
16e771788e
commit
04b9abda3b
@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.ui.menu.DashboardMenuItem;
|
||||
import org.eclipse.hawkbit.ui.push.EventPushStrategy;
|
||||
import org.eclipse.hawkbit.ui.themes.HawkbitTheme;
|
||||
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
|
||||
import org.slf4j.Logger;
|
||||
@@ -121,6 +122,7 @@ public abstract class AbstractHawkbitUI extends UI implements DetachListener {
|
||||
rootLayout.setSizeFull();
|
||||
|
||||
HawkbitCommonUtil.initLocalization(this, uiProperties.getLocalization(), i18n);
|
||||
SPDateTimeUtil.initializeFixedTimeZoneProperty(uiProperties.getFixedTimeZone());
|
||||
|
||||
dashboardMenu.init();
|
||||
dashboardMenu.setResponsive(true);
|
||||
|
||||
@@ -25,6 +25,8 @@ public class UiProperties implements Serializable {
|
||||
|
||||
private boolean gravatar;
|
||||
|
||||
private String fixedTimeZone;
|
||||
|
||||
private final Localization localization = new Localization();
|
||||
|
||||
private final Links links = new Links();
|
||||
@@ -43,6 +45,15 @@ public class UiProperties implements Serializable {
|
||||
this.gravatar = gravatar;
|
||||
}
|
||||
|
||||
public String getFixedTimeZone() {
|
||||
return fixedTimeZone;
|
||||
}
|
||||
|
||||
public void setFixedTimeZone(final String fixedTimeZone) {
|
||||
this.fixedTimeZone = fixedTimeZone;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Localization information
|
||||
*/
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.vaadin.server.WebBrowser;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Common Util to get date/time related information.
|
||||
@@ -27,6 +28,7 @@ public final class SPDateTimeUtil {
|
||||
|
||||
private static final String DURATION_FORMAT = "y','M','d','H','m','s";
|
||||
private static final Map<Integer, CalendarI18N> DURATION_I18N = Maps.newHashMapWithExpectedSize(6);
|
||||
private static String fixedTimeZoneProperty;
|
||||
|
||||
static {
|
||||
DURATION_I18N.put(0, CalendarI18N.YEAR);
|
||||
@@ -41,12 +43,29 @@ public final class SPDateTimeUtil {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get browser time zone.
|
||||
* Set fixed UI timezone
|
||||
*
|
||||
* @param fixedTimeZoneProperty
|
||||
* time zone e.g. Europe/Berlin. If time zone is unknown, it will default to GMT
|
||||
*/
|
||||
public static void initializeFixedTimeZoneProperty(String fixedTimeZoneProperty) {
|
||||
SPDateTimeUtil.fixedTimeZoneProperty = fixedTimeZoneProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get browser time zone or fixed time zone if configured
|
||||
*
|
||||
* @return TimeZone
|
||||
*/
|
||||
public static TimeZone getBrowserTimeZone() {
|
||||
|
||||
|
||||
if (!StringUtils.isEmpty(fixedTimeZoneProperty)) {
|
||||
return TimeZone.getTimeZone(fixedTimeZoneProperty);
|
||||
}
|
||||
|
||||
final WebBrowser webBrowser = com.vaadin.server.Page.getCurrent().getWebBrowser();
|
||||
final String[] timeZones = TimeZone.getAvailableIDs(webBrowser.getRawTimezoneOffset());
|
||||
TimeZone tz = TimeZone.getDefault();
|
||||
|
||||
Reference in New Issue
Block a user