Date-Time Calculation issue OH2 to OH3

As documented in the release notes, DateTime no longer exists in openHAB 3. It’s been replaced by ZonedDateTime. See Rules | openHAB and DateTime Conversion (openHAB 3.x) for lots of examples of working with ZonedDateTime.

Given that we have ZonedDateTimes now, the best approach would probably be to use the stuff built into the classes anyway.

java.time.temporal.ChronoUnit

// in the rule

    var minsToSunset = ChronoUnit.MINUTES.between(now, Sunset_Time.state.getZonedDateTime)

You might need to cast Sunset_Time.state to a DateTimeType.

2 Likes