OH3 JavaScript throws an exception when accessing the previousState of an item in influxdb

Hi everyone,

I am running OH3.1 stable as docker container together with Influxdb2 as persistence.
In my setup I have got an “away”-switch which is toggled when I am out for a longer period of time.
In this case e.g. the thermostats in all rooms are set to a lower level.
On return the thermostats will be reverted to their previous state.

To do the later I want to run the following script:

var PersistenceExtensions = Java.type("org.openhab.core.persistence.extensions.PersistenceExtensions");
var currentItem = "KitchenWallthermostat_ActiveProfile";
var previousState = PersistenceExtensions.previousState(ir.getItem(currentItem),true);
events.sendCommand(currentItem, previousState.getState());

Unfortunately “PersistenceExtensions.previousState(ir.getItem(currentItem),true);” throws the following exception:

[e.automation.internal.RuleEngineImpl] - Fail to execute action: 2
java.lang.IllegalArgumentException: Cannot format given Object as a Date

Digging around I found there already to be an open issue [influxdb] IllegalArgumentException thrown in InfluxDBHistoricItem (Cannot format given Object as a Date) · Issue #9751 · openhab/openhab-addons · GitHub

Btw.: The code above just runs fine if you use try&catch around the critical part and because the result (previousState) is perfectly okay it works as a workaround.

However I was asking myself if that workaround is really the best solution right now ?