Simplify DateTimeType handling for Mercedes Me

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-11-19 21:01:03 +01:00 committed by lsiepel
parent 2f33a2d1ae
commit 164e333a40
2 changed files with 3 additions and 3 deletions

View File

@ -14,6 +14,7 @@ package org.openhab.binding.mercedesme.internal.handler;
import static org.openhab.binding.mercedesme.internal.Constants.*; import static org.openhab.binding.mercedesme.internal.Constants.*;
import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -954,7 +955,7 @@ public class VehicleHandler extends BaseThingHandler {
if (vas != null && !Utils.isNil(vas)) { if (vas != null && !Utils.isNil(vas)) {
// proto weekday starts with MONDAY=0, java ZonedDateTime starts with MONDAY=1 // proto weekday starts with MONDAY=0, java ZonedDateTime starts with MONDAY=1
long estimatedWeekday = Utils.getInt(vas) + 1; long estimatedWeekday = Utils.getInt(vas) + 1;
ZonedDateTime storedZdt = endDateTimeType.getZonedDateTime(); ZonedDateTime storedZdt = endDateTimeType.getZonedDateTime(ZoneId.systemDefault());
long storedWeekday = storedZdt.getDayOfWeek().getValue(); long storedWeekday = storedZdt.getDayOfWeek().getValue();
// check if estimated weekday is smaller than stored // check if estimated weekday is smaller than stored
// estimation Monday=1 vs. stored Saturday=6 => (7+1)-6=2 days ahead // estimation Monday=1 vs. stored Saturday=6 => (7+1)-6=2 days ahead

View File

@ -107,8 +107,7 @@ public class Utils {
* @return openHAB DateTimeType according to configured TimeZone * @return openHAB DateTimeType according to configured TimeZone
*/ */
public static DateTimeType getDateTimeType(long ms) { public static DateTimeType getDateTimeType(long ms) {
Instant timestamp = Instant.ofEpochMilli(ms); return new DateTimeType(Instant.ofEpochMilli(ms));
return new DateTimeType(timestamp.atZone(timeZoneProvider.getTimeZone()));
} }
/** /**