Skip to content

Commit

Permalink
Use configured time-zone when converting DateTimeType to `ZonedDate…
Browse files Browse the repository at this point in the history
…Time` (#408)

Related to openhab/openhab-core#3583.
Resolves #404.

This removes usages of the deprecated `DateTimeType` method 
[getZonedDateTime()](https://www.openhab.org/javadoc/latest/org/openhab/core/library/types/datetimetype#getZonedDateTime())
and instead applies the time-zone configured in openHAB.

Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur authored Dec 23, 2024
1 parent b9da72a commit 29c6231
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function _convertItemRawState (rawState) {
} else if (rawState instanceof StringType) { // String type Items
return _parseString(rawState.toString());
} else if (rawState instanceof DateTimeType) { // DateTime Items
return javaZDTToJsZDT(rawState.getZonedDateTime());
return javaInstantToJsInstant(rawState.getInstant()).atZone(time.ZoneId.systemDefault());
} else if (rawState instanceof QuantityType) { // Number:Time type Items
return _addQuantityType(rawState);
} else {
Expand Down Expand Up @@ -288,10 +288,10 @@ function toZDT (when) {
return _addMillisToNow(when.floatValue());
}

// DateTimeType, extract the javaZDT and convert to time.ZDT
// DateTimeType, extract the javaInstant and convert to time.ZDT, use the configured timezone
if (when instanceof DateTimeType) {
log.debug('toZTD: Converting DateTimeType ' + when);
return javaZDTToJsZDT(when.getZonedDateTime());
log.debug('toZDT: Converting DateTimeType ' + when);
return javaInstantToJsInstant(when.getInstant()).atZone(time.ZoneId.systemDefault());
}

// Add Quantity or QuantityType<Time> to now
Expand Down

0 comments on commit 29c6231

Please sign in to comment.