isBetweenTimes fails after upgrade to OH4

I have some JSScripting code working before the upgrade from OH 3.4 to 4.03

if (time.toZDT().isBetweenTimes(items.getItem('MorningStart'), items.getItem('DayStart'))) {
    // do some stuff
}

but after the upgrade,it gives an exception:

2023-11-05 14:59:50.479 [ERROR] [nhab.automation.script.file.house.js] - Failed to execute rule Initialise-DayPeriod-a23bdd32-b316-45ea-b24d-44b5b7caab04: Error: "MorningStart (Type=DateTimeItem, State=1970-01-01T07:00:00.000+0100, Label=Morning start time, Category=Time)" is an unsupported type for conversion to time.ZonedDateTime: Error: "MorningStart (Type=DateTimeItem, State=1970-01-01T07:00:00.000+0100, Label=Morning start time, Category=Time)" is an unsupported type for conversion to time.ZonedDateTime

I’m running openHABian on a Pi4, and upgraded by flashing the latest openHABian to a new SD card, then restored the 3.4 backup with menu option 04.
All my old rules are working fine except for this one.

I have re-installed JSScripting (using MainUI) but it didn’t help.

Can anyone suggest what to try>

There is a known bug in 4.0.3 where time.toZDT() fails to recognize an Item. I think it’s been corrected in the 4.1 milestones.

In 4.0, you can work around the problem by simply using items.getItem('MorningStart').state instead.