Skip to content

Commit e794c6a

Browse files
jlaurlsiepel
authored andcommitted
Simplify DateTimeType handling for InfluxDB
Signed-off-by: Jacob Laursen <[email protected]>
1 parent bc540c6 commit e794c6a

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

bundles/org.openhab.persistence.influxdb/src/main/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtils.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
import java.math.BigDecimal;
1616
import java.time.Instant;
17-
import java.time.ZonedDateTime;
18-
import java.util.TimeZone;
1917

2018
import javax.measure.Unit;
2119

@@ -85,7 +83,7 @@ public static Object stateToObject(State state) {
8583
} else if (state instanceof OpenClosedType) {
8684
value = state == OpenClosedType.OPEN ? DIGITAL_VALUE_ON : DIGITAL_VALUE_OFF;
8785
} else if (state instanceof DateTimeType type) {
88-
value = type.getZonedDateTime().toInstant().toEpochMilli();
86+
value = type.getInstant().toEpochMilli();
8987
} else {
9088
value = state.toFullString();
9189
}
@@ -140,9 +138,7 @@ public static State objectToState(@Nullable Object value, Item itemToSetState) {
140138
} else if (item instanceof RollershutterItem) {
141139
return new PercentType(valueStr);
142140
} else if (item instanceof DateTimeItem) {
143-
Instant i = Instant.ofEpochMilli(new BigDecimal(valueStr).longValue());
144-
ZonedDateTime z = ZonedDateTime.ofInstant(i, TimeZone.getDefault().toZoneId());
145-
return new DateTimeType(z);
141+
return new DateTimeType(Instant.ofEpochMilli(new BigDecimal(valueStr).longValue()));
146142
} else if (item instanceof PlayerItem) {
147143
try {
148144
return PlayPauseType.valueOf(valueStr);

bundles/org.openhab.persistence.influxdb/src/test/java/org/openhab/persistence/influxdb/internal/InfluxDBStateConvertUtilsTest.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import java.math.BigDecimal;
2323
import java.time.Instant;
24-
import java.time.ZoneId;
2524
import java.time.ZonedDateTime;
2625

2726
import javax.measure.Unit;
@@ -130,8 +129,7 @@ public void convertDateTimeToState() {
130129
long val = System.currentTimeMillis();
131130
DateTimeItem item = new DateTimeItem("name");
132131

133-
DateTimeType expected = new DateTimeType(
134-
ZonedDateTime.ofInstant(Instant.ofEpochMilli(val), ZoneId.systemDefault()));
132+
DateTimeType expected = new DateTimeType(Instant.ofEpochMilli(val));
135133
assertThat(InfluxDBStateConvertUtils.objectToState(val, item), equalTo(expected));
136134
}
137135

0 commit comments

Comments
 (0)