mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Simplify DateTimeType handling for Deutsche Bahn
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
e05d5ba84a
commit
1f6f05ab83
@ -14,8 +14,6 @@ package org.openhab.binding.deutschebahn.internal;
|
|||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -297,8 +295,7 @@ public final class EventAttribute<VALUE_TYPE, STATE_TYPE extends State>
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
final ZonedDateTime d = ZonedDateTime.ofInstant(value.toInstant(), ZoneId.systemDefault());
|
return new DateTimeType(value.toInstant());
|
||||||
return new DateTimeType(d);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,6 @@ package org.openhab.binding.deutschebahn.internal;
|
|||||||
import static org.mockito.ArgumentMatchers.*;
|
import static org.mockito.ArgumentMatchers.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
@ -102,8 +100,7 @@ public class DeutscheBahnTrainHandlerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static State getDateTime(final Date day) {
|
private static State getDateTime(final Date day) {
|
||||||
final ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(day.toInstant(), ZoneId.systemDefault());
|
return new DateTimeType(day.toInstant());
|
||||||
return new DateTimeType(zonedDateTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -15,8 +15,6 @@ package org.openhab.binding.deutschebahn.internal;
|
|||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
@ -147,8 +145,7 @@ public class EventAttributeTest {
|
|||||||
public void testPlannedTime() {
|
public void testPlannedTime() {
|
||||||
String time = "2109111825";
|
String time = "2109111825";
|
||||||
GregorianCalendar expectedValue = new GregorianCalendar(2021, 8, 11, 18, 25, 0);
|
GregorianCalendar expectedValue = new GregorianCalendar(2021, 8, 11, 18, 25, 0);
|
||||||
DateTimeType expectedState = new DateTimeType(
|
DateTimeType expectedState = new DateTimeType(expectedValue.toInstant());
|
||||||
ZonedDateTime.ofInstant(expectedValue.toInstant(), ZoneId.systemDefault()));
|
|
||||||
doTestEventAttribute("planned-time", null, (Event e) -> e.setPt(time), expectedValue.getTime(), expectedState,
|
doTestEventAttribute("planned-time", null, (Event e) -> e.setPt(time), expectedValue.getTime(), expectedState,
|
||||||
EventType.DEPARTURE, true);
|
EventType.DEPARTURE, true);
|
||||||
}
|
}
|
||||||
@ -157,8 +154,7 @@ public class EventAttributeTest {
|
|||||||
public void testChangedTime() {
|
public void testChangedTime() {
|
||||||
String time = "2109111825";
|
String time = "2109111825";
|
||||||
GregorianCalendar expectedValue = new GregorianCalendar(2021, 8, 11, 18, 25, 0);
|
GregorianCalendar expectedValue = new GregorianCalendar(2021, 8, 11, 18, 25, 0);
|
||||||
DateTimeType expectedState = new DateTimeType(
|
DateTimeType expectedState = new DateTimeType(expectedValue.toInstant());
|
||||||
ZonedDateTime.ofInstant(expectedValue.toInstant(), ZoneId.systemDefault()));
|
|
||||||
doTestEventAttribute("changed-time", null, (Event e) -> e.setCt(time), expectedValue.getTime(), expectedState,
|
doTestEventAttribute("changed-time", null, (Event e) -> e.setCt(time), expectedValue.getTime(), expectedState,
|
||||||
EventType.DEPARTURE, true);
|
EventType.DEPARTURE, true);
|
||||||
}
|
}
|
||||||
@ -167,8 +163,7 @@ public class EventAttributeTest {
|
|||||||
public void testCancellationTime() {
|
public void testCancellationTime() {
|
||||||
String time = "2109111825";
|
String time = "2109111825";
|
||||||
GregorianCalendar expectedValue = new GregorianCalendar(2021, 8, 11, 18, 25, 0);
|
GregorianCalendar expectedValue = new GregorianCalendar(2021, 8, 11, 18, 25, 0);
|
||||||
DateTimeType expectedState = new DateTimeType(
|
DateTimeType expectedState = new DateTimeType(expectedValue.toInstant());
|
||||||
ZonedDateTime.ofInstant(expectedValue.toInstant(), ZoneId.systemDefault()));
|
|
||||||
doTestEventAttribute("cancellation-time", null, (Event e) -> e.setClt(time), expectedValue.getTime(),
|
doTestEventAttribute("cancellation-time", null, (Event e) -> e.setClt(time), expectedValue.getTime(),
|
||||||
expectedState, EventType.DEPARTURE, true);
|
expectedState, EventType.DEPARTURE, true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user