DateTime in rule v2.3

I cant for the life of me get a datetime field to be compared against now - the latest ive tried is:

var DateTime dateTime = new DateTime((CalendarTimeStart1.state as DateTimeType).calendar.timeInMillis)
		if (dateTime.plusMinutes(30).isBefore(now)) {
		testend.postUpdate("yer")
		}
		else {
			testend.postUpdate("nar")
		}


it always ends in the log:

2018-02-18 17:15:02.828 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Calendar Reminder': Could not cast 2018-02-18T17:15:02.827+10:30 to org.eclipse.smarthome.core.library.types.DateTimeType; line 129, column 42, length 19your code goes here

ive tried using

new DateTime((CalendarTimeStart1.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)

with same result

Can anyone help?

ultimately I am trying to check that a calendar event’s start time is 60 minutes before “now” so I can create a calendar reminder.

Using nightlies at v2.3

What item type is CalendarTimeStart1 ? It’s .state appears to be returning a string.

I got it to work - code here:

        val DateTime CheckTimeStart = new DateTime((CalendarTimeStart1.state as DateTimeType).calendar.timeInMillis)
		val DateTime roundedeventstart = CheckTimeStart.minuteOfDay().roundFloorCopy
		val DateTime roundednow = now.minuteOfDay().roundFloorCopy
	
		if (roundednow.plusMinutes(60) == roundedeventstart) {
	      	Echo_Living_Room_Remind.sendCommand("You have a calendar event " + CalendarName1.state + " starting in 60 minutes")
        }

I get a warning that getcalendar is deprecated - anyone know what I should be using to get the same result?

This is ultimately doing the job but I have to check the value every minute so it matches the next up calendar event - if anyone can think of a tidier way Id be grateful

Try this

val DateTime CheckTimeStart = new DateTime((CalendarTimeStart1.state as DateTimeType).getZonedDateTime.toInstant.toEpochMilli)

Thanks - I thought I had something in there like that before but tried many things and failed - no errors yet will see what happens at the next calendar reminder!