Hi all. I have a problem with a JS rule in OH 5.2.0.M5 that I cannot explain myself. The code looks as follows:
const command = event.receivedCommand.toString();
var chosenDateTime = time.toZDT(command);
var timeOn = chosenDateTime.minusDays(1)
.withHour(11)
.withMinute(0)
.withSecond(0)
.withNano(0);
const relativeTime = timeOn.fromNow();
The error I am getting is TypeError: timeOn.fromNow is not a function on the last line. I believe this code used to work in OH 5.1.4, but I am not 100% sure. Is there anything odd going on with type conversion?
Great, thanks a lot @uk59821 ! I wished the JavaScript API would change less frequently. Given the dynamically typed nature of JavaScript it is quite hard to avoid these issues.
According to the docs, this was added in OH 5.0 but it’s always been getMillisFromNow(). Perhaps fromNow() was an undocumented feature. The developers take great care not to change the opengab-js API and when something does have to change there is a period where the old way is still supported but generates deprecation warnings.
But that’s not done for undocumented features as those features are not officially part of the API in the first place.