historicState dont work with jython in OH3

I cant get historicState to work in jython, but averageSince works fine.

I tried to call historicState in rules file, and that works fine.

Jython code:

@rule(baseName+".System started")
@when("System started")
def test4Started(event):
    from core.actions import PersistenceExtensions
    test4Started.log.info(baseName+" started")
    date = ZonedDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0)
    test4Started.log.info(unicode(date))
    test4Started.log.info(unicode(type(date)))
    test4Started.log.info(unicode(PersistenceExtensions.averageSince(ir.getItem("DayAheadPricesMaxPrice"), date, "influxdb")))
    test4Started.log.info(unicode(PersistenceExtensions.historicState(ir.getItem("DayAheadPricesMaxPrice"), date, "influxdb")))
    

log:

2022-12-04 10:08:17.926 [INFO ] [sr223.jython.test4.py.System started] - test4.py started
2022-12-04 10:08:17.928 [INFO ] [sr223.jython.test4.py.System started] - 2022-12-04T00:00+01:00[Europe/Paris]
2022-12-04 10:08:17.930 [INFO ] [sr223.jython.test4.py.System started] - <type 'java.time.ZonedDateTime'>
2022-12-04 10:08:17.938 [INFO ] [sr223.jython.test4.py.System started] - 6.02
2022-12-04 10:08:17.987 [WARN ] [jsr223.jython                       ] - Traceback (most recent call last):
  File "/openhab/conf/automation/lib/python/core/log.py", line 96, in wrapper
    return function(*args, **kwargs)
  File "/openhab/conf/automation/lib/python/core/rules.py", line 108, in execute
    self.callback(inputs.get('event'))
  File "/openhab/conf/automation/jsr223/python/personal/test4.py", line 59, in test4Started
    test4Started.log.info(unicode(PersistenceExtensions.historicState(ir.getItem("DayAheadPricesMaxPrice"), date, "influxdb")))
IllegalArgumentException: java.lang.IllegalArgumentException: Cannot format given Object as a Date

rules file:

val date = ZonedDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0)
logInfo("test5.rules", date.toString())
logInfo("test5.rules", "historicState " + date.toString() +" - influxdb: " + DayAheadPricesMaxPrice.historicState(date, "influxdb").state)

log:

2022-12-04 10:04:56.984 [INFO ] [penhab.core.model.script.test5.rules] - 2022-12-04T00:00+01:00[Europe/Paris]
2022-12-04 10:04:57.009 [INFO ] [penhab.core.model.script.test5.rules] - historicState 2022-12-04T00:00+01:00[Europe/Paris] - influxdb: 5.71

Maybe you can split the lines so we can see if the issue occurs in unicode(...) or in historicState(...).

if i added .state after it worked

test4Started.log.info(unicode(PersistenceExtensions.historicState(ir.getItem("DayAheadPricesMaxPrice"), date, "influxdb")))
    

to

test4Started.log.info(unicode(PersistenceExtensions.historicState(ir.getItem("DayAheadPricesMaxPrice"), date, "influxdb").state))