Issue of the topic: timer.getExecutionTime().ISOString() does not work.
Hi all,
little problem with timers in JAVASCRIPT rules:
I like to get the execution time of a timer as outlined here https://www.openhab.org/addons/automation/jsscripting/#createtimer to put it into an item of datetime type.
var timer = actions.ScriptExecution.createTimer(‘TimerName’, now.plusMinutes ( delayMins ), timerFunction );
var timeString = timer.getExecutionTime().ISOString(); // does not work amoung lots of other possible conversion
→ … [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID ‘…’ failed: org.graalvm.polyglot.PolyglotException:
TypeError: invokeMember (toISOString) on java.time.ZonedDateTime@6c8101aa failed due to: Unknown identifier: toISOString
// only this works
var timeString = timer.getExecutionTime().toString();
// workaround:
execTimeItem.postUpdate ( new Date ( mt.getExecutionTime() ).toISOString() ) ;
The …toISOString() method was presented by the rules editor when starting ‘Intellisense’ or whatever that is named when you press ‘.’ and ‘space’. So my idea was, it is present.
I’m pretty sure that because we are working with the raw Java openHAB Timer Object that it’s the Java ZonedDateTime Object and not a JS Object. When in doubt, time.toZDT() will always return the JS ZonedDateTime. Though I don’t think toISOString() exists there either. In fact by default toString() already returns the ISO String so there’d be no need.
But in a pinch that’s one way to tell the difference between a Java ZDT and JS ZDT: when you log it the Java ZDT will show the timezone as words in brackets (e.g. [America/Denver]) and the JS ZDT will show it as +/- hours from zulu.