Skip to content

Commit

Permalink
[easee] fix date formatting issues (#15501)
Browse files Browse the repository at this point in the history
* fix DateTimeException when formatting date out of range (in this case Instant.MIN)

Signed-off-by: Alexander Friese <af944580@googlemail.com>
  • Loading branch information
alexf2015 authored and jlaur committed Aug 30, 2023
1 parent ce17091 commit 20a2ef5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

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;
Expand Down Expand Up @@ -67,18 +65,6 @@ public static ZonedDateTime parseDate(String date) throws DateTimeParseException
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ private void processAuthenticationResult(CommunicationStatus status, JsonObject
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());

statusHandler.updateStatusInfo(ThingStatus.ONLINE, ThingStatusDetail.NONE,
STATUS_TOKEN_VALIDATED);
Expand Down Expand Up @@ -225,7 +225,7 @@ private synchronized void refreshAccessToken() {
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);
refreshCommand.registerResultProcessor(this::processAuthenticationResult);
Expand Down

0 comments on commit 20a2ef5

Please sign in to comment.