running OH 4.2.0-release on openHABian since upgrade from 4.1.2.
I’m trying to compare an JSON delivered date with the current time.
the item TIB_Prices
is a JSON with the current value:
[
{
"startsAt": "2024-07-19T00:00:00.000+02:00",
"total": 0.2934
},
{
"startsAt": "2024-07-19T01:00:00.000+02:00",
"total": 0.2819
}#, ... all the other hours
]
The following comparison worked within OH 4.1.2:
var jetzt = time.LocalDateTime.now().minusMinutes(59);
var checkPrice = JSON.parse(items.getItem("TIB_Prices").state);
if (jetzt > checkPrice[0].startsAt) {
// do something
}
which now throws an error:
2024-07-18 16:30:00.626 [ERROR] [n.script.javascript.checkItemChanges] - Failed to execute script: TypeError: A conversion from Temporal to a number is not allowed. To compare use the methods .equals(), .compareTo(), .isBefore() or one that is more suitable to your use case.
at <js>.:anonymous(@openhab-globals.js:2)
at <js>.letztesUpdateIstPassiert(<eval>:20)
at <js>.:program(<eval>:34)
at org.graalvm.polyglot.Context.eval(Context.java:399)
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458)
... 23 more
2024-07-18 16:30:00.627 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'checkItemChanges' failed: org.graalvm.polyglot.PolyglotException: TypeError: A conversion from Temporal to a number is not allowed. To compare use the methods .equals(), .compareTo(), .isBefore() or one that is more suitable to your use case.
So I have to rewrite all of that? but how? (I’m at a complete loss with the various date formats and dat comparisons). I tried to lookup “.isBefore”, which lead me to this monster (which supposedly works? )
var jetzt = time.toZDT(time.LocalDateTime.now().minusMinutes(59).toString());
var checkPrice = JSON.parse(items.getItem("TIB_Prices").state);
if (jetzt.isAfterDateTime(time.toZDT(checkPrice[0].startsAt)) {
// do something
}
is it really THAT complex? or is there some better solution (I hope!)?
I did not find a way to “minusMinutes” or “plusHours” with time.toZDT
… and do I have to convert into a zonedDateTime? I found an documentation for JavaScript, in which the “isBefore”-part was mentioned as “can also be string”?