i am using OH3 and want to do a simple date comparison.
This was working in OH2 but in OH3 its not - which sucks.
var DateTimeType prevOnState
var jetzt = new DateTimeType()
prevOnState = Praesenz_Innen_Zuletzt_Wann.state as DateTimeType
diff = Seconds::secondsBetween(new DateTime(prevOnState.zonedDateTime.toInstant().toEpochMilli), now ).getSeconds()
Can someone explain me how to get the difference(in seconds, milliseconds or minutes).
Working with time data has its quirks. It is never simple.
Life’s no pony farm. Read the OH 3.0 release notes on relevant changes w.r.t. joda time classes.
rules DSL isn’t java. Time calculations can be nasty, true, but there’s no feasible other way than to sit down and fiddle with the code until you understand it. The link @Sascha_Billian gave has more or less all the information it takes.
var long diff = jetzt.getZonedDateTime.toEpochSecond - prevOnState.getZonedDateTime.toEpochSecond
if (jetzt.getZonedDateTime.toEpochSecond > prevOnState.getZonedDateTime.toEpochSecond)