Simplify DateTimeType handling for Shelly

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-11-16 00:46:58 +01:00 committed by lsiepel
parent 751bbf7495
commit 96b5ad2e55
2 changed files with 1 additions and 6 deletions

View File

@ -345,7 +345,6 @@ public class ShellyManagerPage {
value = dateTimeState.format(null).replace('T', ' ').replace('-', '/');
break;
default:
value = getTimestamp(dateTimeState);
value = dateTimeState.format(null).replace('T', ' ').replace('-', '/');
}
} else {

View File

@ -304,17 +304,13 @@ public class ShellyUtils {
ZoneId zoneId = !zone.isEmpty() ? ZoneId.of(zone) : ZoneId.systemDefault();
ZonedDateTime zdt = LocalDateTime.now().atZone(zoneId);
int delta = zdt.getOffset().getTotalSeconds();
return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochSecond(timestamp - delta), zoneId));
return new DateTimeType(Instant.ofEpochSecond(timestamp - delta));
} catch (DateTimeException e) {
// Unable to convert device's timezone, use system one
return getTimestamp();
}
}
public static String getTimestamp(DateTimeType dt) {
return dt.getZonedDateTime().toString().replace('T', ' ').replace('-', '/');
}
public static String convertTimestamp(long ts) {
if (ts == 0) {
return "";