I’m trying compare and calculate difference between two DateTime items but it doesn’t work. Despite I have tried different approaches I always get some error. This was my last try:
Heating_setpoints.allMembers.forEach[sp|
val String baseName = sp.name.split("_").get(0)+"_"+sp.name.split("_").get(1)
var last_update = Heating_lastupdates.allMembers.findFirst[m|m.name.startsWith(baseName)].state as DateTimeType
var mins_between = last_update.until(now, ChronoUnit.MINUTES)
]
I got following error: 'until' is not a member of 'org.eclipse.smarthome.core.library.types.DateTimeType'; line 150,
My aim is to check if last_update is older than one hour. Could you please help me?
Thank you,
Convert your DateTimeType to a ZonedDateTime, and then you can use its until method. But you will need to use a ZonedDateTime instead of a Joda DateTime…
var mins_between = last_update.zonedDateTime.until(new DateTimeType().zonedDateTime, ChronoUnit.MINUTES)
Hi 5iver,
Thank you for your quick reply, but I still get the following error:
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Heating - Check Demand': 'zoneedDateTime' is not a member of 'org.eclipse.smarthome.core.library.types.DateTimeType';
last_update value looks ok because when I write that into log I get this for example:
var last_update = Heating_lastupdates.allMembers.findFirst[m|m.name.startsWith(baseName)].state as DateTimeType
logInfo("rules", "lastupdate: "+last_update)
var mins_between = last_update.zonedDateTime.until(new DateTimeType().zoneedDateTime, ChronoUnit.MINUTES)
Hi,
I got an error message again: [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Heating - Check Demand': The name 'ChronoUnit' cannot be resolved to an item or type;