From 1f6f05ab831903ebe8586c3a116abefa32930408 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 10 Dec 2024 21:40:25 +0100 Subject: [PATCH] Simplify DateTimeType handling for Deutsche Bahn Signed-off-by: Jacob Laursen --- .../binding/deutschebahn/internal/EventAttribute.java | 5 +---- .../internal/DeutscheBahnTrainHandlerTest.java | 5 +---- .../deutschebahn/internal/EventAttributeTest.java | 11 +++-------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/EventAttribute.java b/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/EventAttribute.java index a21e9564062..5100cf3f12a 100644 --- a/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/EventAttribute.java +++ b/bundles/org.openhab.binding.deutschebahn/src/main/java/org/openhab/binding/deutschebahn/internal/EventAttribute.java @@ -14,8 +14,6 @@ package org.openhab.binding.deutschebahn.internal; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -297,8 +295,7 @@ public final class EventAttribute if (value == null) { return null; } else { - final ZonedDateTime d = ZonedDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault()); - return new DateTimeType(d); + return new DateTimeType(value.toInstant()); } } diff --git a/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/DeutscheBahnTrainHandlerTest.java b/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/DeutscheBahnTrainHandlerTest.java index bf19c30cbe5..5bcdacc6380 100644 --- a/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/DeutscheBahnTrainHandlerTest.java +++ b/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/DeutscheBahnTrainHandlerTest.java @@ -15,8 +15,6 @@ package org.openhab.binding.deutschebahn.internal; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.Arrays; import java.util.Date; import java.util.GregorianCalendar; @@ -102,8 +100,7 @@ public class DeutscheBahnTrainHandlerTest { } private static State getDateTime(final Date day) { - final ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(day.toInstant(), ZoneId.systemDefault()); - return new DateTimeType(zonedDateTime); + return new DateTimeType(day.toInstant()); } @Test diff --git a/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/EventAttributeTest.java b/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/EventAttributeTest.java index 587caa50079..67b1edb80fb 100644 --- a/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/EventAttributeTest.java +++ b/bundles/org.openhab.binding.deutschebahn/src/test/java/org/openhab/binding/deutschebahn/internal/EventAttributeTest.java @@ -15,8 +15,6 @@ package org.openhab.binding.deutschebahn.internal; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.GregorianCalendar; @@ -147,8 +145,7 @@ public class EventAttributeTest { public void testPlannedTime() { String time = "2109111825"; GregorianCalendar expectedValue = new GregorianCalendar(2021, 8, 11, 18, 25, 0); - DateTimeType expectedState = new DateTimeType( - ZonedDateTime.ofInstant(expectedValue.toInstant(), ZoneId.systemDefault())); + DateTimeType expectedState = new DateTimeType(expectedValue.toInstant()); doTestEventAttribute("planned-time", null, (Event e) -> e.setPt(time), expectedValue.getTime(), expectedState, EventType.DEPARTURE, true); } @@ -157,8 +154,7 @@ public class EventAttributeTest { public void testChangedTime() { String time = "2109111825"; GregorianCalendar expectedValue = new GregorianCalendar(2021, 8, 11, 18, 25, 0); - DateTimeType expectedState = new DateTimeType( - ZonedDateTime.ofInstant(expectedValue.toInstant(), ZoneId.systemDefault())); + DateTimeType expectedState = new DateTimeType(expectedValue.toInstant()); doTestEventAttribute("changed-time", null, (Event e) -> e.setCt(time), expectedValue.getTime(), expectedState, EventType.DEPARTURE, true); } @@ -167,8 +163,7 @@ public class EventAttributeTest { public void testCancellationTime() { String time = "2109111825"; GregorianCalendar expectedValue = new GregorianCalendar(2021, 8, 11, 18, 25, 0); - DateTimeType expectedState = new DateTimeType( - ZonedDateTime.ofInstant(expectedValue.toInstant(), ZoneId.systemDefault())); + DateTimeType expectedState = new DateTimeType(expectedValue.toInstant()); doTestEventAttribute("cancellation-time", null, (Event e) -> e.setClt(time), expectedValue.getTime(), expectedState, EventType.DEPARTURE, true); }