Skip to content

Commit

Permalink
Use configured time-zone when converting DateTimeType to ZonedDateTime
Browse files Browse the repository at this point in the history
Resolves #404

Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur committed Dec 18, 2024
1 parent ca90fa6 commit 1a85f58
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 1a85f58

Please sign in to comment.