diff --git a/bundles/org.openhab.binding.bigassfan/src/main/java/org/openhab/binding/bigassfan/internal/handler/BigAssFanHandler.java b/bundles/org.openhab.binding.bigassfan/src/main/java/org/openhab/binding/bigassfan/internal/handler/BigAssFanHandler.java index 2cfff155bec87..b8669a32592b0 100644 --- a/bundles/org.openhab.binding.bigassfan/src/main/java/org/openhab/binding/bigassfan/internal/handler/BigAssFanHandler.java +++ b/bundles/org.openhab.binding.bigassfan/src/main/java/org/openhab/binding/bigassfan/internal/handler/BigAssFanHandler.java @@ -25,11 +25,11 @@ import java.net.UnknownHostException; import java.nio.BufferOverflowException; import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; import java.util.Arrays; -import java.util.Calendar; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; @@ -41,7 +41,6 @@ import java.util.regex.Pattern; import org.apache.commons.lang.StringUtils; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.smarthome.core.common.ThreadPoolManager; import org.eclipse.smarthome.core.library.types.DateTimeType; import org.eclipse.smarthome.core.library.types.OnOffType; @@ -86,7 +85,7 @@ public class BigAssFanHandler extends BaseThingHandler { protected Map fanStateMap = Collections.synchronizedMap(new HashMap<>()); - public BigAssFanHandler(@NonNull Thing thing, String ipv4Address) { + public BigAssFanHandler(Thing thing, String ipv4Address) { super(thing); this.thing = thing; @@ -990,10 +989,8 @@ private void updateTime(String[] messageParts) { logger.debug("Process time update for {}: {}", thing.getUID(), messageParts[3]); // (mac|name;TIME;VALUE;2017-03-26T14:06:27Z) try { - Calendar cal = Calendar.getInstance(); Instant instant = Instant.parse(messageParts[3]); - cal.setTime(Date.from(instant)); - DateTimeType state = new DateTimeType(cal); + DateTimeType state = new DateTimeType(ZonedDateTime.ofInstant(instant, ZoneId.systemDefault())); updateChannel(CHANNEL_TIME, state); fanStateMap.put(CHANNEL_TIME, state); } catch (DateTimeParseException e) { diff --git a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java index 1479431f8fce9..b62af9d39643c 100644 --- a/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java +++ b/bundles/org.openhab.binding.gardena/src/main/java/org/openhab/binding/gardena/internal/handler/GardenaThingHandler.java @@ -15,6 +15,8 @@ import static org.openhab.binding.gardena.internal.GardenaBindingConstants.*; import static org.openhab.binding.gardena.internal.GardenaSmartCommandName.*; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Map; import java.util.Map.Entry; @@ -185,7 +187,7 @@ private State convertToState(Device device, ChannelUID channelUID) throws Garden case "DateTime": Calendar cal = DateUtils.parseToCalendar(value); if (cal != null && !cal.before(VALID_DATE_START)) { - return new DateTimeType(cal); + return new DateTimeType(ZonedDateTime.ofInstant(cal.toInstant(), ZoneId.systemDefault())); } else { return UnDefType.NULL; } diff --git a/bundles/org.openhab.binding.logreader/src/main/java/org/openhab/binding/logreader/internal/handler/LogHandler.java b/bundles/org.openhab.binding.logreader/src/main/java/org/openhab/binding/logreader/internal/handler/LogHandler.java index e9a440a163fe8..3db263fceb2eb 100644 --- a/bundles/org.openhab.binding.logreader/src/main/java/org/openhab/binding/logreader/internal/handler/LogHandler.java +++ b/bundles/org.openhab.binding.logreader/src/main/java/org/openhab/binding/logreader/internal/handler/LogHandler.java @@ -14,7 +14,8 @@ import static org.openhab.binding.logreader.internal.LogReaderBindingConstants.*; -import java.util.Calendar; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.regex.PatternSyntaxException; import org.eclipse.smarthome.core.library.types.DateTimeType; @@ -162,7 +163,7 @@ public void fileNotFound() { @Override public void fileRotated() { logger.debug("Log rotated"); - updateChannelIfLinked(CHANNEL_LOGROTATED, new DateTimeType(Calendar.getInstance())); + updateChannelIfLinked(CHANNEL_LOGROTATED, new DateTimeType(ZonedDateTime.now())); } @Override diff --git a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/grxprg/PrgProtocolHandler.java b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/grxprg/PrgProtocolHandler.java index a1485fdc23120..048816f065015 100644 --- a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/grxprg/PrgProtocolHandler.java +++ b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/grxprg/PrgProtocolHandler.java @@ -13,6 +13,8 @@ package org.openhab.binding.lutron.internal.grxprg; import java.io.IOException; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Calendar; import java.util.HashMap; import java.util.Map; @@ -884,7 +886,8 @@ private void handleReportTime(Matcher m, String resp) { final int yr = Integer.parseInt(m.group(5)); c.set(Calendar.YEAR, yr + (yr < 50 ? 1900 : 2000)); - _callback.stateChanged(PrgConstants.CHANNEL_TIMECLOCK, new DateTimeType(c)); + _callback.stateChanged(PrgConstants.CHANNEL_TIMECLOCK, + new DateTimeType(ZonedDateTime.ofInstant(c.toInstant(), ZoneId.systemDefault()))); } catch (NumberFormatException e) { logger.error("Invalid time response (can't parse number): '{}'", resp); } @@ -934,12 +937,14 @@ private void handleSunriseSunset(Matcher m, String resp) { final Calendar sunrise = Calendar.getInstance(); sunrise.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(1))); sunrise.set(Calendar.MINUTE, Integer.parseInt(m.group(2))); - _callback.stateChanged(PrgConstants.CHANNEL_SUNRISE, new DateTimeType(sunrise)); + _callback.stateChanged(PrgConstants.CHANNEL_SUNRISE, + new DateTimeType(ZonedDateTime.ofInstant(sunrise.toInstant(), ZoneId.systemDefault()))); final Calendar sunset = Calendar.getInstance(); sunset.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(3))); sunset.set(Calendar.MINUTE, Integer.parseInt(m.group(4))); - _callback.stateChanged(PrgConstants.CHANNEL_SUNSET, new DateTimeType(sunset)); + _callback.stateChanged(PrgConstants.CHANNEL_SUNSET, + new DateTimeType(ZonedDateTime.ofInstant(sunset.toInstant(), ZoneId.systemDefault()))); } catch (NumberFormatException e) { logger.error("Invalid sunrise/sunset response (can't parse number): '{}'", resp); } diff --git a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/TimeclockHandler.java b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/TimeclockHandler.java index 598e127b89c53..8b7fc26f2ad76 100644 --- a/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/TimeclockHandler.java +++ b/bundles/org.openhab.binding.lutron/src/main/java/org/openhab/binding/lutron/internal/handler/TimeclockHandler.java @@ -14,6 +14,8 @@ import static org.openhab.binding.lutron.internal.LutronBindingConstants.*; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Calendar; import org.eclipse.jdt.annotation.NonNullByDefault; @@ -180,13 +182,15 @@ public void handleUpdate(LutronCommandType type, String... parameters) { } else if (parameters.length >= 2 && ACTION_SUNRISE.toString().equals(parameters[0])) { Calendar calendar = parseLutronTime(parameters[1]); if (calendar != null) { - updateState(CHANNEL_SUNRISE, new DateTimeType(calendar)); + updateState(CHANNEL_SUNRISE, + new DateTimeType(ZonedDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault()))); } } else if (parameters.length >= 2 && ACTION_SUNSET.toString().equals(parameters[0])) { Calendar calendar = parseLutronTime(parameters[1]); if (calendar != null) { - updateState(CHANNEL_SUNSET, new DateTimeType(calendar)); + updateState(CHANNEL_SUNSET, + new DateTimeType(ZonedDateTime.ofInstant(calendar.toInstant(), ZoneId.systemDefault()))); } } else if (parameters.length >= 2 && ACTION_EXECEVENT.toString().equals(parameters[0])) { diff --git a/bundles/org.openhab.binding.meteoblue/src/main/java/org/openhab/binding/meteoblue/internal/handler/MeteoBlueHandler.java b/bundles/org.openhab.binding.meteoblue/src/main/java/org/openhab/binding/meteoblue/internal/handler/MeteoBlueHandler.java index 98844d8b440bc..ca11e40fd0e5e 100644 --- a/bundles/org.openhab.binding.meteoblue/src/main/java/org/openhab/binding/meteoblue/internal/handler/MeteoBlueHandler.java +++ b/bundles/org.openhab.binding.meteoblue/src/main/java/org/openhab/binding/meteoblue/internal/handler/MeteoBlueHandler.java @@ -19,6 +19,8 @@ import java.io.IOException; import java.math.BigDecimal; import java.math.RoundingMode; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Calendar; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; @@ -230,7 +232,8 @@ private void updateChannel(String channelId) { // Build a State from this value State state = null; if (datapoint instanceof Calendar) { - state = new DateTimeType((Calendar) datapoint); + state = new DateTimeType( + ZonedDateTime.ofInstant(((Calendar) datapoint).toInstant(), ZoneId.systemDefault())); } else if (datapoint instanceof Integer) { state = getStateForType(channel.getAcceptedItemType(), (Integer) datapoint); } else if (datapoint instanceof Number) { diff --git a/bundles/org.openhab.binding.onebusaway/src/main/java/org/openhab/binding/onebusaway/internal/handler/RouteHandler.java b/bundles/org.openhab.binding.onebusaway/src/main/java/org/openhab/binding/onebusaway/internal/handler/RouteHandler.java index e461652dea138..8918d22d496a2 100644 --- a/bundles/org.openhab.binding.onebusaway/src/main/java/org/openhab/binding/onebusaway/internal/handler/RouteHandler.java +++ b/bundles/org.openhab.binding.onebusaway/src/main/java/org/openhab/binding/onebusaway/internal/handler/RouteHandler.java @@ -14,6 +14,9 @@ import static org.openhab.binding.onebusaway.internal.OneBusAwayBindingConstants.*; +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Calendar; import java.util.List; import java.util.Map; @@ -165,7 +168,8 @@ private void updatePropertiesFromArrivalAndDeparture(ArrivalAndDeparture data) { private void publishChannel(ChannelUID channelUID, Calendar now, long lastUpdateTime, List arrivalAndDepartures) { if (channelUID.getId().equals(CHANNEL_ID_UPDATE)) { - updateState(channelUID, new DateTimeType((new Calendar.Builder()).setInstant(lastUpdateTime).build())); + updateState(channelUID, new DateTimeType( + ZonedDateTime.ofInstant(Instant.ofEpochMilli(lastUpdateTime), ZoneId.systemDefault()))); return; } @@ -197,7 +201,8 @@ private void publishChannel(ChannelUID channelUID, Calendar now, long lastUpdate logger.debug("Not notifying {} because it is in the past.", channelUID.getId()); continue; } - updateState(channelUID, new DateTimeType(time)); + updateState(channelUID, + new DateTimeType(ZonedDateTime.ofInstant(time.toInstant(), ZoneId.systemDefault()))); // Update properties only when we update arrival information. This is not perfect. if (channelUID.getId().equals(CHANNEL_ID_ARRIVAL)) { diff --git a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java index c4220d87bbd0c..936b50e461f31 100644 --- a/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java +++ b/bundles/org.openhab.binding.tellstick/src/main/java/org/openhab/binding/tellstick/internal/handler/TelldusDevicesHandler.java @@ -15,6 +15,8 @@ import static org.openhab.binding.tellstick.internal.TellstickBindingConstants.*; import java.math.BigDecimal; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Calendar; import org.eclipse.smarthome.config.core.Configuration; @@ -266,7 +268,8 @@ public void onDeviceStateChanged(Bridge bridge, Device device, TellstickEvent ev } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(event.getTimestamp()); - updateState(timestampChannel, new DateTimeType(cal)); + updateState(timestampChannel, + new DateTimeType(ZonedDateTime.ofInstant(cal.toInstant(), ZoneId.systemDefault()))); } } diff --git a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiClientThingHandler.java b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiClientThingHandler.java index f4e05c28ee562..931d2d87b8cc8 100644 --- a/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiClientThingHandler.java +++ b/bundles/org.openhab.binding.unifi/src/main/java/org/openhab/binding/unifi/internal/handler/UniFiClientThingHandler.java @@ -16,6 +16,8 @@ import static org.eclipse.smarthome.core.thing.ThingStatusDetail.CONFIGURATION_ERROR; import static org.openhab.binding.unifi.internal.UniFiBindingConstants.*; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Calendar; import org.apache.commons.lang.StringUtils; @@ -194,7 +196,8 @@ protected void refreshChannel(UniFiClient client, ChannelUID channelUID) { case CHANNEL_LAST_SEEN: // mgb: we don't check clientOnline as lastSeen is also included in the Insights data if (client.getLastSeen() != null) { - state = new DateTimeType(client.getLastSeen()); + state = new DateTimeType( + ZonedDateTime.ofInstant(client.getLastSeen().toInstant(), ZoneId.systemDefault())); } break;