]> git.basschouten.com Git - openhab-addons.git/commitdiff
[easee] fix date formatting issues (#15501)
authorAlexander Friese <alexf2015@users.noreply.github.com>
Wed, 30 Aug 2023 18:10:23 +0000 (20:10 +0200)
committerGitHub <noreply@github.com>
Wed, 30 Aug 2023 18:10:23 +0000 (20:10 +0200)
* fix DateTimeException when formatting date out of range (in this case Instant.MIN)

Signed-off-by: Alexander Friese <af944580@googlemail.com>
bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/EaseeBindingConstants.java
bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/Utils.java
bundles/org.openhab.binding.easee/src/main/java/org/openhab/binding/easee/internal/connector/WebInterface.java

index 2c97616dd56ada2c3b330624bd649943bf518284..239ea2d06f30d6972d60e39a644a03b60ed930ec 100644 (file)
@@ -171,7 +171,7 @@ public class EaseeBindingConstants {
     public static final String THING_CONFIG_BACK_PLATE_ID = "backPlateId";
     public static final String THING_CONFIG_MASTER_BACK_PLATE_ID = "masterBackPlateId";
 
-    public static final Instant OUTDATED_DATE = Instant.MIN;
+    public static final Instant OUTDATED_DATE = Instant.EPOCH;
     public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
 
     public static final String PARAMETER_NAME_WRITE_COMMAND = "writeCommand";
index 01d6a1dc45eb8ac639f23a996b8ada1b6e558ad2..4dbe0311ebd96831ba62228e53f7fe42f7a5a52c 100644 (file)
@@ -14,8 +14,6 @@ package org.openhab.binding.easee.internal;
 
 import static org.openhab.binding.easee.internal.EaseeBindingConstants.*;
 
-import java.time.Instant;
-import java.time.ZoneId;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
@@ -67,18 +65,6 @@ public final class Utils {
         return zdt;
     }
 
-    /**
-     * returns a date in a readable format
-     *
-     * @param date
-     * @return
-     */
-    public static String formatDate(Instant date) {
-        final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
-                .withZone(ZoneId.systemDefault());
-        return formatter.format(date);
-    }
-
     /**
      * get element as JsonObject.
      *
index c14c8e7eef481f60c77bca3ffbfca134f34ed72b..657f97a4929047fa8aa730a351673334c88ce634 100644 (file)
@@ -149,8 +149,8 @@ public class WebInterface implements AtomicReferenceTrait {
                         tokenRefreshDate = Instant.now();
                         tokenExpiry = tokenRefreshDate.plusSeconds(expiresInSeconds);
 
-                        logger.debug("access token refreshed: {}, expiry: {}", Utils.formatDate(tokenRefreshDate),
-                                Utils.formatDate(tokenExpiry));
+                        logger.debug("access token refreshed: {}, expiry: {}", tokenRefreshDate.toString(),
+                                tokenExpiry.toString());
 
                         bridgeStatusHandler.updateStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE,
                                 STATUS_TOKEN_VALIDATED);
@@ -226,7 +226,7 @@ public class WebInterface implements AtomicReferenceTrait {
             if (now.plus(WEB_REQUEST_TOKEN_EXPIRY_BUFFER_MINUTES, ChronoUnit.MINUTES).isAfter(tokenExpiry)
                     || now.isAfter(tokenRefreshDate.plus(WEB_REQUEST_TOKEN_MAX_AGE_MINUTES, ChronoUnit.MINUTES))) {
                 logger.debug("access token needs to be refreshed, last refresh: {}, expiry: {}",
-                        Utils.formatDate(tokenRefreshDate), Utils.formatDate(tokenExpiry));
+                        tokenRefreshDate.toString(), tokenExpiry.toString());
 
                 EaseeCommand refreshCommand = new RefreshToken(handler, accessToken, refreshToken,
                         this::processAuthenticationResult);