Skip to content

Commit

Permalink
Simplify DateTimeType handling for InfluxDB
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur committed Nov 17, 2024
1 parent 1e4573b commit d65b5ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import java.math.BigDecimal;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.TimeZone;

import javax.measure.Unit;

Expand Down Expand Up @@ -140,9 +138,7 @@ public static State objectToState(@Nullable Object value, Item itemToSetState) {
} else if (item instanceof RollershutterItem) {
return new PercentType(valueStr);
} else if (item instanceof DateTimeItem) {
Instant i = Instant.ofEpochMilli(new BigDecimal(valueStr).longValue());
ZonedDateTime z = ZonedDateTime.ofInstant(i, TimeZone.getDefault().toZoneId());
return new DateTimeType(z);
return new DateTimeType(Instant.ofEpochMilli(new BigDecimal(valueStr).longValue()));
} else if (item instanceof PlayerItem) {
try {
return PlayPauseType.valueOf(valueStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.math.BigDecimal;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

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

DateTimeType expected = new DateTimeType(
ZonedDateTime.ofInstant(Instant.ofEpochMilli(val), ZoneId.systemDefault()));
DateTimeType expected = new DateTimeType(Instant.ofEpochMilli(val));
assertThat(InfluxDBStateConvertUtils.objectToState(val, item), equalTo(expected));
}

Expand Down

0 comments on commit d65b5ae

Please sign in to comment.