Skip to content

Commit

Permalink
[astro] Method renamed (relative to TimeZoneProvider)
Browse files Browse the repository at this point in the history
Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo committed Jun 9, 2020
1 parent c75b067 commit 392376c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public class AstroHandlerFactory extends BaseThingHandlerFactory {
private final CronScheduler scheduler;

@Activate
public AstroHandlerFactory(final @Reference CronScheduler scheduler, final @Reference TimeZoneProvider timeZone) {
public AstroHandlerFactory(final @Reference CronScheduler scheduler,
final @Reference TimeZoneProvider timeZoneProvider) {
this.scheduler = scheduler;
PropertyUtils.setTimeZone(timeZone);
PropertyUtils.setTimeZoneProvider(timeZoneProvider);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
*/
package org.openhab.binding.astro.internal.config;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
Expand Down Expand Up @@ -68,15 +64,8 @@ public void setThingUid(String thingUid) {

@Override
public String toString() {
TimeZone tz = TimeZone.getDefault();
StringBuilder tzInfo = new StringBuilder();
tzInfo.append(tz.getID());
tzInfo.append(" (").append(tz.getDisplayName(false, TimeZone.SHORT)).append(" ")
.append(new SimpleDateFormat("Z").format(Calendar.getInstance().getTime()));
tzInfo.append(")");
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("thing", thingUid)
.append("geolocation", geolocation).append("altitude", altitude).append("interval", interval)
.append("systemTimezone", tzInfo.toString())
.append("daylightSavings", Calendar.getInstance().get(Calendar.DST_OFFSET) != 0).toString();
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,8 @@ public static State getState(ChannelUID channelUID, AstroChannelConfig config, O
}
}

public static void setTimeZone(TimeZoneProvider zone) {
PropertyUtils.timeZoneProvider = zone;
}

public static void unsetTimeZone() {
PropertyUtils.timeZoneProvider = null;
public static void setTimeZoneProvider(TimeZoneProvider timeZoneProvider) {
PropertyUtils.timeZoneProvider = timeZoneProvider;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ public static List<Object[]> data() {

@Test
public void testParametrized() {
PropertyUtils.unsetTimeZone();

// Anonymous implementation of the service to adapt the time zone to the tested longitude and latitude
PropertyUtils.setTimeZone(new TimeZoneProvider() {
PropertyUtils.setTimeZoneProvider(new TimeZoneProvider() {
@Override
public ZoneId getTimeZone() {
return ZONE_ID;
Expand Down

0 comments on commit 392376c

Please sign in to comment.