Simplify DateTimeType handling for Deutsche Bahn

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Jacob Laursen 2024-12-10 21:40:25 +01:00 committed by Ciprian Pascu
parent 2dc9d9c29e
commit 9c3b40a9bc
3 changed files with 5 additions and 16 deletions

View File

@ -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<VALUE_TYPE, STATE_TYPE extends State>
if (value == null) {
return null;
} else {
final ZonedDateTime d = ZonedDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault());
return new DateTimeType(d);
return new DateTimeType(value.toInstant());
}
}

View File

@ -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

View File

@ -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);
}